Jump to content

Recommended Posts

Hi all,

 

I've tried two ways but I cannot get this to work...Basically I'm trying to change the value strings in $row['GARAGEDESC'] to several human readable words...

 

Below string is currently stored in  $row['GARAGEDESC']

 

PARATTACHE,PAROPENER,PARREAR

 

Below is the code...

 

$Garage = $row['GARAGEDESC'];
								$search = array('[PARSWING]','[PARNONE]','[PARGOLFCAR]','[PARUNCOV]','[PARWKBENCH]','[PARUNASSIG]','[PAROVERSIZ]','[PARREAR]','[PARCOVERED]','[PARPORT-CH]','[PAROTHER]','[PAROPENER]','[PARDETACH]','[PARATTACHE]','[PARSIDE]','[PARCONVERS]','[PARASSIGN]','[PARTANDEM]','[PARSINK]','[PAROUT-ENT]','[PARFRONT]','[PARCIRCLE]');
								$replace = array('Swing Drive','None','Golf Cart Garage','Uncovered','Workbench','Unassigned','Oversized','Rear','Covered','Porte-Cochere','Other','Opener','Detached','Attached','Side','Garage Conversion','Assign','Tandem Style','Has Sink in Garage','Outside Entry','Front','Circle Drive');
								$msg=str_replace($search,$replace,$Garage);
								echo $msg;	

 

I've also tried this...

 

								str_replace("PARSWING","Swing Drive",$Garage);
								str_replace("PARNONE","None",$Garage);
								str_replace("PARGOLFCAR","Golf Cart Garage",$Garage);
								str_replace("PARUNCOV","Uncovered",$Garage);
								str_replace("PARWKBENCH","Workbench",$Garage);
								str_replace("PARUNASSIG","Unassigned",$Garage);
								str_replace("PAROVERSIZ","Oversized",$Garage);
								str_replace("PARREAR","Rear",$Garage);
								str_replace("PARCOVERED","Covered",$Garage);
								str_replace("PARPORT-CH","Porte-Cochere",$Garage);
								str_replace("PAROTHER","Other",$Garage);
								str_replace("PAROPENER","Opener",$Garage);
								str_replace("PARDETACH","Detached",$Garage);
								str_replace("PARATTACHE","Attached",$Garage);
								str_replace("PARSIDE","Side",$Garage);
								str_replace("PARCONVERS","Garage Conversion",$Garage);
								str_replace("PARASSIGN","Assign",$Garage);
								str_replace("PARTANDEM","Tandem Style",$Garage);
								str_replace("PARSINK","Has Sink in Garage",$Garage);
								str_replace("PAROUT-ENT","Outside Entry",$Garage);
								str_replace("PARFRONT","Front",$Garage);
								str_replace("PARCIRCLE","Circle Drive",$Garage);

 

None of them are working... Any ideas????

Link to comment
https://forums.phpfreaks.com/topic/205928-multiple-str_replace-not-working/
Share on other sites

Well, the multiple str_replaces do not work because you never assign the replaced variable back to $Garage.

 

The first one does not work because you have [ ] around the words in the replace array. Remove those brackets and it should work just fine for ya.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.