Page 1 of 1

Scratching head on regular expressions

Posted: Wed Dec 03, 2003 4:28 am
by Nay
I've got my regex to change URLs to Links. I also have my bbcode to replace tags. [syntax=php]<?php function for ... earch4 = "";
$replace4 = "</a>";
$str = str_replace($search4, $replace4, $str);

$search5 = "[/font]";
$replace5 = "</span>";
$str = str_replace($search5, $replace5, $str);

$search6 = "]";
$replace6 = "">";
$str = str_replace($search6, $replace6, $str);

$search7 = "[font size=";
$replace7 = "<span style="font-size:";
$str = str_replace($search7, $replace7, $str);

$search8 = "[url=";
$replace8 = "<a rel="external" href="";
$str = str_replace($search8, $replace8, $str);

return $str;

}

$text = <<< END
this is some text that has been
processed by php to replace the bbcode. this is a
link
http://www.xanga.com
http://forums.devnetwork.net
and that is [font size=20]big[/font]. look this is
my e-mail naymyo89@hotmail.com
END;

$text = format($text);

echo $text;

?>[/syntax]

Okay, it looks fine but when it's al done I get:

Code: Select all

&lt;strong&gt;this&lt;/strong&gt; is some text that has been&lt;br /&gt;
&lt;em&gt;processed&lt;/em&gt; by php to replace the &lt;u&gt;bbcode&lt;/u&gt;. this is a&lt;br /&gt;
&lt;a rel="external" href="&lt;a href="http://yahoo.com rel="external"&gt;http://yahoo.com&lt;/a&gt;"&gt;link&lt;/a&gt; &lt;br /&gt;
&lt;a href="http://www.xanga.com" rel="external"&gt;www.xanga.com&lt;/a&gt;&lt;br /&gt;
&lt;a rel="external" href="&lt;a href="http://forums.devnetwork.net rel="external"&gt;http://forums.devnetwork.net&lt;/a&gt;&lt;/a&gt;&lt;br /&gt;

and that is &lt;span style="font-size:20"&gt;big&lt;/span&gt;. look this is&lt;br /&gt;
my e-mail &lt;a href="mailto:naymyo89@hotmail.com"&gt;naymyo89@hotmail.com&lt;/a&gt;
How do I fix:

Code: Select all

&lt;a rel="external" href="&lt;a href="http://yahoo.com rel="external"&gt;http://yahoo.com&lt;/a&gt;"&gt;link&lt;/a&gt;
that from happening? <_<

-Nay