-3
<?php
$price= str_replace("\\", " ", $objVehicleData->getPrice());
$price= str_replace(",", " ", $price);
$price= str_replace("$", " ",$price);
$price= str_replace(" ", "",$price);
?>

The above code works.. But I am certain it can be made better in one line.. Can someone help please

John Conde
  • 217,595
  • 99
  • 455
  • 496
Hello Universe
  • 3,248
  • 7
  • 50
  • 86

1 Answers1

4
$price= str_replace(array("\\", ",", "$", " "), "", $objVehicleData->getPrice());

From the manual:

If search and replace are arrays, then str_replace() takes a value from each array and uses them to search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string, then this replacement string is used for every value of search.

John Conde
  • 217,595
  • 99
  • 455
  • 496