Jump to content

Problem with str_replace


mvoelkening

Recommended Posts

Hello,

 

I use the following code to replace some values with a set of different values:

 

$old=array("101000","101300","101200","101100","101900","101700","102000","101600","101500","102100","101800","101400","111000","111100","111200","111300","111400","111600","111500","201300","211600","201100","211500","201000","201200","210000","211400","211000","211200","211300","211100","211400","130000","140000","131100","131200","131300","121000","122000","123000","300000","301000","301600","301100","301200","301400","301500","301900","301700","301800","311600","310000","301100","311200","311300","311400","311500","320000","321000","321300","321100","321200","321400","321500","400000","401000","401100","401200","401300","401400","401500","401600","410000","411000","411100","411200","411500","411400","411600","411800","411900","411700","420000","421000","421300","421100","421200","411300","600000","510000","500000","501000","501100","501200","501300","501400","501600","501700","501800","501900","502000","502100","502200","502300","502400","502500","502600","502700","503000","502800","503100","503200","301300","507200","500200","432000","431000");
$new=array("100000","200000","210000","220000","300000","310000","320000","330000","330000","350000","360000","370000","400000","411000","412000","413000","414000","420000","430000","500000","510000","510000","530000","530000","540000","550000","551000","552000","553000","553000","554000","555000","600000","601000","601000","601000","601000","603000","604000","605000","700000","701000","703000","704000","705000","706000","707000","708000","709000","709000","709000","710000","711000","712000","713000","713000","714000","720000","721000","723000","723000","723000","723000","723000","730000","731000","732000","733000","734000","735000","736000","737000","740000","741000","742000","743000","744000","744000","745000","746000","747000","748000","750000","751000","752000","753000","756000","757000","800000","810000","780000","781000","781100","781200","781300","781400","781600","781700","781800","781900","782000","782100","782200","782300","782400","782500","782600","782700","783000","782800","783100","783200","702000","","","","");
$categories_new=str_replace($old,$new,$categories);
 

So if $categories='101900' then this code first replaces it with 300000 but then it replaces the 300000 with 700000. I don't want that. I just want the 101900 replaced with 300000 and the same with all the other texts. $categories can contain mulitple values like '101900 300000' which should be converted to '300000 700000' because 101900 should be converted to 300000 and 300000 to 700000. How do I do this?

 

Thanks for your help

 

Martin

Link to comment
https://forums.phpfreaks.com/topic/278050-problem-with-str_replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.