quote:
Originally posted by J-Thread
code:
$string = preg_replace('/\[\[wiki(?:\:|)([a-zA-Z]+|)\]([a-zA-z0-9]+)\]/e', 'defL("$1","$2")',$string);
function defL($lang,$title){
if($lang=='')$lang='en';
return "<a href='http://$lang.wikipedia.org/wiki/$title'>" . str_replace("_", " ", $title) . "</a>";
}
That also replaces the _ to spaces. Ok I didn't knew something like this did exist, really interesting. This is the final one, and is the best option I think.
Maybe replace $lang='en' by $lang='www', so people are sended to the default language of wikipedia, and maybe to there own language if wikipedia introduces a language check...
code:
$string = preg_replace('/\[\[wiki(?:\:|)([a-zA-Z]+|)\]([a-zA-z0-9_]+)\]/e', 'defL("$1","$2")',$string);
function defL($lang,$title){
if($lang=='')$lang='en';
$title1 = str_replace("_", " ", $title);
return "<a href='http://$lang.wikipedia.org/wiki/$title'>$title1</a>";
}
looks neater
oh and i also added the _ to the regexp capture part.