|
bb code link
| Author | |
| Description | Replaces [url=http://....]test[/link] with real html links. |
| Rating | (5 votes) |
PHP Code
function replaceUrl($message) {
// Make link from [url]htp://.... [/url] or [url=http://.... ]text[/url]
if (strpos($message, "[url")){
$begUrl = strpos($message, "[url");
$endUrl = strpos($message, "[/url]");
$url = substr($message, $begUrl, $endUrl-$begUrl+6);
$posBracket = strpos($url, "]");
if ($posBracket != null){
if ($posBracket == 4){
// [url]http://.... [/url]
$link = substr($url, 5, $endUrl - $begUrl -5);
$htmlUrl = "<a href=$link target='_blank'>$link</A>";
} else {
// [url=http://....]text[/url]
$link = substr($url, 5, $posBracket-5);
$text = substr($url, $posBracket+1, strpos($url, "[/url]") - $posBracket-1);
$htmlUrl = "<a href=$link target='main'>$text</A>";
}
}
$message = str_replace($url, $htmlUrl, $message);
// searches for other [url]-nodes
$message = replaceUrl($message);
}
return $message;
}
Comments
No comments posted yet.
|