homepage Welcome to WebmasterWorld Guest from 54.161.155.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php preg replace array
jman11




msg:4022209
 6:26 am on Nov 10, 2009 (gmt 0)

how do you replace a value with an array of values several times?

 

JohnCanyon




msg:4022474
 4:49 pm on Nov 10, 2009 (gmt 0)

$find_array = array('foo','bar');
$replace_array = array('moo','car');

$string = 'foo bar';
echo str_replace($find_array, $replace_array, $string);

//outputs
moo car

jman11




msg:4022668
 9:47 pm on Nov 10, 2009 (gmt 0)

everyone does replace with both find an array and the replace an array. how do you do it with just the replace an array?

JohnCanyon




msg:4022715
 10:42 pm on Nov 10, 2009 (gmt 0)

Because, the occurance of the first element in the replace array would overwrite all occurances of the find making the additional replaces irrelevant.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved