code:
function wiki_link($input) {
$i = 0;
$output = "";
while($i < strlen($input)) {
$searchfor = "[[wiki";
if(substr($input, $i, strlen($searchfor)) == $searchfor) {
if($input{$i+strlen($searchfor)} == ":") {
$next = strpos($input, "]", $i);
$lang = substr($input, $i+strlen($searchfor)+1, $next - ($i+strlen($searchfor)) - 1);
$next2 = strpos($input, "]", $next + 1);
$thestr = substr($input, $next + 1, $next2 - $next - 1);
$output .= "<a href=\"http://" . $lang . ".wikipedia.org/wiki/" . $thestr . "\">" . str_replace("_", " ", $thestr) . "</a>";
$i = $next2 + 1;
}
elseif($input{$i+strlen($searchfor)} == "]") {
$next = strpos($input, "]", $i+strlen($searchfor)+1);
$thestr = substr($input, $i+strlen($searchfor) + 1, $next - ($i+strlen($searchfor)) - 1);
$output .= "<a href=\"http://www.wikipedia.org/wiki/" . $thestr . "\">" . str_replace("_", " ", $thestr) . "</a>";
$i = $next + 1;
}
else {
$output .= $searchfor;
$i += strlen($searchfor);
}
}
else {
$output .= $input{$i};
$i++;
}
}
return $output;
}
May look a bit complicated, but i don't think there is a better option, and it works so...have fun with it