Problem with PCRE (preg_replace) and PHP4 Beta 3...
| From: | Kris Erickson | Date: | Fri, 19 Nov 1999 22:32:51 +0000 |
| Subject: | Problem with PCRE (preg_replace) and PHP4 Beta 3... | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-6536@lists.php.net to get a copy of this message | ||
There is either a bug with PCRE or with PHP4 Beta 3... Back references
somehow lose their reference after the first occurance. They generally
point to nothing or junk... Following is a q&d example of where it gets
confused... Haven't yet tried compiling the earlier version of PCRE in yet
to see if that that is the problem...
Code:
<HTML><BODY><PRE>
<?
$str = "Here is a link <A HREF=\"www.php.net\">PHP</A> and here
is
another <A HREF=\"www.mha.ca\">mha</A> and here is
a third <A HREF=\"www.zend.com\">zend</A>";
echo "Before: $str\n\n";
$str =
preg_replace("/(?<!http:\/\/)(www\.\w{0,50}\.\w{2,3})/i","http://\\1",$str);
echo "After: $str\n\n";
?>
</PRE></BODY></HTML>
Raw Output of PHP4 Beta 2 (pcre 2.05)
<HTML><BODY><PRE>
<?
$str = "Here is a link <A HREF=\"www.php.net\">PHP</A> and here
is
another <A HREF=\"www.mha.ca\">mha</A> and here is
a third <A HREF=\"www.zend.com\">zend</A>";
echo "Before: $str\n\n";
$str =
preg_replace("/(?<!http:\/\/)(www\.\w{0,50}\.\w{2,3})/i","http://\\1",$str);
echo "After: $str\n\n";
?>
</PRE></BODY></HTML>
Raw output of PHP4 Beta 3 (pcre 2.08)
<HTML><BODY><CODE>
Before:
Here is a link <A HREF="www.php.net">PHP</A> and here is another <A
HREF="www.mha.ca">mha</A> and here is a third <A
HREF="www.zend.com">zend</A>
After:
Here is a link <A HREF="http://www.php.net">PHP</A> and here is another
<A
HREF="http://hird <A HR">mha</A> and here is a third
<A
HREF="http://sion">zend</A>
</CODE></BODY></HTML>
Kris Erickson
MacDonald Harris and Associates
www.mha.ca