note 100119 deleted from function.preg-replace by danbrown

From: Date: Mon, 20 Jun 2011 15:19:41 +0000
Subject: note 100119 deleted from function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180736@lists.php.net to get a copy of this message
Note Submitter: tomfmason ---- in response to rysiek You can do something like: <?php function replace_named($string,$args) { foreach($args as $k=>$v) { $string = preg_replace("/\(\?P\<$k\>(.*)\)/",$v,$string); } return $string; } $string = 'articles/(?P<year>\d{4})'; $args = array('year'=>2010); echo replace_named($string,$args); ?>

« previous php.notes (#180736) next »