Ok... I'm fairly new to PHP, and very new to this forum (looks promising). But, I have found my way around PHP thus far without too many hookups. However, I do have a problem using the preg_replace function. I am trying to remove the [url]http://[/url] tag from returns from a MySQL database.... I have some sucess, until certain characters appear.... ie -, ?, etc. Is there a method of maintaining urls with extra characters?
Here is the code....
<?
$link1 = "http://www.phpbuilder.com/";
$link2 = "http://www.cnn.com/SPECIALS/2003/iraq/";
$link1 = preg_replace("/\b((http(s?):\/\/)|(www\.))([\w\.]+)([\/\w+\.]+)\b/i", "<u><a href=\"http$3://$4$5$6\" target=\"_blank\">$4$5$6</a></u>", $link1);
$link2 = preg_replace("/\b((http(s?):\/\/)|(www\.))([\w\.]+)([\/\w+\.]+)\b/i", "<u><a href=\"http$3://$4$5$6\" target=\"_blank\">$4$5$6</a></u>", $link2);
echo "$link1\n\r<br>";
echo "$link2\n\r<br>";
?>
Example
Thanks 😉