note 37522 added to function.preg-replace

From: Date: Tue, 18 Nov 2003 19:29:44 +0000
Subject: note 37522 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-60582@lists.php.net to get a copy of this message
I had some text with numbers that I wanted to use as array references in the replacement text- here's how it worked for me: $string="My name is [0]"; $names=array("Bill","Bob","Joe"); $string = preg_replace("/\[(\d+)\]/",$names[(int) ${1}],$string); echo $string; output should be "My name is Bill"... Took me just a bit of playing around to figure this out (newbie), so I thought I would post it here. ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37522 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37522&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37522&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60582) next »