Friday 16 August 2019

Replace multiple words with Str_Replace PHP 8

How to replace multiple synonyms with one specific word using PHP


$a = array( 'truck', 'vehicle', 'seddan', 'coupe' );
 
$str = 'Honda is a truck. Toyota is a vehicle. Nissan is a sedan. Scion is a coupe.';
echo str_replace($a,'car',str_replace('Lexus','Toyota',$str));

This will replace vehicle->car and so on

Demo http://ideone.com/0I37nX
Previous Post
Next Post

post written by:

0 Comments:

Hit me with a comment!