I want to replace multiple synonyms with one specific word.
<?p
$a = array(
'truck',
'vehicle',
'seddan',
'coupe',
'Toyota',
);
$b = array(
'car',
'car',
'car',
'car',
'Lexus',
);
$str = '
Honda is a truck.
Toyota is a vehicle.
Nissan is a sedan.
Scion is a coupe.
';
echo str_replace($a,$b,$str);
?>
RESULT: Honda is a car. Lexus is a car. Nissan is a car. Scion is a car.
Can someone show me a clean way of replacing "vehicle, truck, coupe, sedan" with the word "car" instead of me replacing all 4 of them individually. Thank you.
$a = array( 'truck', 'vehicle', 'sedan', '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('Toyota','Lexus',$str));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With