note 37522 deleted from function.preg-replace by tularis

From: Date: Sun, 18 Jun 2006 13:15:30 +0000
Subject: note 37522 deleted from function.preg-replace by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114296@lists.php.net to get a copy of this message
Note Submitter: jlyman at oregontech dot net ---- 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.

« previous php.notes (#114296) next »