Jump to content

Hi is there a way to use str_replace to replace if find two values?


Lisa23

Recommended Posts

hi is there a way of doing a str replace to look twice

like at moment i have if find space replace with "-"

PHP Code:

 .str_replace(' ','-',($row['model']))  

is there a way i can do if find twice

$row['model

if find space " " replace with "-" also if find "i30" replace with "10"

is there a way i can try find another like if find " " replace with "-" also if find "130" replace with hello world??

 

thanks in advance

HYi thanks for the link i found out that i can do it this way

// Provides: You should eat pizza, beer, and ice cream every day
$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy   = array("pizza", "beer", "ice cream");

$newphrase = str_replace($healthy, $yummy, $phrase);

but is there a way that i can just implement

.str_replace(' ','-','cars','bikes'($row['model']))  

is there?

No, you can't just add arguments.  You can inline the array's if you want, but if your number of replacements gets large it's more readable to have them separate.

 

str_replace(array(' ', '-'), array('cars', 'bikes'), $row['model']);

 

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.