ToonMariner Posted July 25, 2007 Share Posted July 25, 2007 Done this before and can't bloody replicate it... I have a string that contains place holders like so... Hello #name# and welcome to playgroup. You are #age# and have #limbs#. I have an array like so.. <?php $data['name'] = 'George'; $data['age'] = 3; $data['limbs'] = 4; ?> so I want to replace #XX# with the corresponding index in the array... something like... preg_replace('/#(.)*?#/',$data['$1'],$str); but I just can't get it... Please help before my monitor takes a hit. Link to comment https://forums.phpfreaks.com/topic/61682-solved-grrrrrrrrrrrr/ Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 You'll need the /e modifier (execute substitution as PHP code). preg_replace('/#(.)*?#/e',"$data[$1]",$str); Link to comment https://forums.phpfreaks.com/topic/61682-solved-grrrrrrrrrrrr/#findComment-307175 Share on other sites More sharing options...
ToonMariner Posted July 26, 2007 Author Share Posted July 26, 2007 I got it to work - but with the replacement string singled quoted (double quoted failed!) THANK YOU - you are a gentleman and a scholar. Link to comment https://forums.phpfreaks.com/topic/61682-solved-grrrrrrrrrrrr/#findComment-307831 Share on other sites More sharing options...
DeadEvil Posted July 26, 2007 Share Posted July 26, 2007 try this.. preg_replace('/#([A-Za-z0-9])?#/e',"$data[$1]",$str); Link to comment https://forums.phpfreaks.com/topic/61682-solved-grrrrrrrrrrrr/#findComment-307850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.