quote:
Originally posted by Ezra
I'm trying to mod my blog a little, I want to add a function that automaticly adds Wikipedia links.
So when i type [[wiki]RAM] It makes it <a href="http://en.wikipedia.org/wiki/RAM">RAM</a>
Preg is better, IMO.
code:
$string = preg_replace("/\[\[wiki\](.+)\]/i", '<a href="http://en.wikipedia.org/wiki/$1">$1</a>', $string);
quote:
And maybe even support for different languages like
[[wiki:nl]RAM] for http://nl.wikipedia.org/wiki/RAM and
[[wiki:en]RAM] for http://en.wikipedia.org/wiki/RAM
I'm not really a hero with advanced string replacers , so any help is appreciated
code:
$string = preg_replace("/\[\[wiki:([a-z]{2})\](.+)\]/i", '<a href="http://$1.wikipedia.org/wiki/$2">$2</a>', $string);
Not sure, didn't test it. Variable name should be changed to the variable name you use for your post text.
Edit: corrected a lot of typos
Edit 2: @ WDZ => preg_ > ereg/i
Edit 3: can be quite buggy if you use many tags in the same post... cbb to fix it