note 87764 added to function.preg-replace-callback
| From: | nicolaspar at gmail dot com | Date: | Sat, 20 Dec 2008 02:33:17 +0000 |
| Subject: | note 87764 added to function.preg-replace-callback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148377@lists.php.net to get a copy of this message | ||
To spend more than one parameter can do the following (note the "e" parameter in
preg_replace function)
<?
$array = array(
1=>'ONE',
2=>'TWO',
3=>'Three'
);
function search(&$array, $str, $foo, $bar){
return ( empty($array[$str]) ? '['.$foo.'-'.$bar.']' : $array[$str]
);
}
function keys(&$array, $str,$foo,$bar){
return preg_replace('/\[(.*?)\]/e',"search(\$array,$1,\$foo,\$bar)",$str);
}
$str = "One [1] Two [2] Three [3], Other parameter [22]";
echo keys($array, $str,'Foo','Bar');
?>
Nice
----
Server IP: 190.2.55.3
Probable Submitter: 190.138.62.190
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php
Edit -- https://master.php.net/note/edit/87764
Del: integrated -- https://master.php.net/note/delete/87764/integrated
Del: useless -- https://master.php.net/note/delete/87764/useless
Del: bad code -- https://master.php.net/note/delete/87764/bad+code
Del: spam -- https://master.php.net/note/delete/87764/spam
Del: non-english -- https://master.php.net/note/delete/87764/non-english
Del: in docs -- https://master.php.net/note/delete/87764/in+docs
Del: other reasons-- https://master.php.net/note/delete/87764
Reject -- https://master.php.net/note/reject/87764
Search -- https://master.php.net/manage/user-notes.php