note 43788 added to function.preg-replace
| From: | llbra at phpbrasil dot php dot net | Date: | Sat, 03 Jul 2004 20:33:08 +0000 |
| Subject: | note 43788 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72483@lists.php.net to get a copy of this message | ||
For those who are experiencing problems with reference in preg_replace() perheaps it´s a good idea
to use preg_replace_callback() that makes things more clear and easy to manipulate when we are
dealing with a bigger or more complex replacing regex or even non working in my case.
<?php
/*$fCt = preg_replace("'<A
HREF=\"?guid-([0-9]{1,2}).html\"?>([^<]+?)</A>'is",
"<A HREF=\"$f[$\\1]\">\\2</A>",$fCt);*/ // didn´t worked !
function repLinks($m){
global $f;
settype($m[1],"int");
return "<A HREF=\"{$f[$m[1]-1]}\">$m[2]</A>";
}
$fCt = preg_replace_callback("'<A
HREF=\"?guid-([0-9]{1,2}).html\"?>([^<]+?)</A>'is",
"repLinks",$fCt);
?>
this one worked just fine and helped in this trouble that no one could solve in the list.
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43788
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43788&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43788&report=yes
Search -- http://master.php.net/manage/user-notes.php