note 43788 deleted from function.preg-replace by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 03 Jul 2004 20:34:07 +0000 |
| Subject: | note 43788 deleted from function.preg-replace by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72484@lists.php.net to get a copy of this message | ||
Note Submitter: llbra@phpbrasil
----
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.