note 59022 deleted from function.str-replace by bjori
| From: | bjori@php.net | Date: | Sun, 26 Mar 2006 22:17:52 +0000 |
| Subject: | note 59022 deleted from function.str-replace by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106658@lists.php.net to get a copy of this message | ||
Note Submitter: martin at lannsjo dot com
----
Found a small bug in mdn_abn's code. A url like this [url=http://www.something.com?test=123] didnt work
correctly.
function fixHTML($message=''){
// Make link from [url]htp://.... [/url] or [url=http://.... ]text[/url]
while(strpos($message, "[url")!==false){
$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=\\"_blank\\">$text</a>";
}
}
$message = str_replace($url, $htmlUrl, $message);
// searches for other [url]-nodes
}
return $message;
}