So far I have :
$q = str_replace(' ','/',$q);
$q = str_replace(',','/',$q);
$q = str_replace('\-','/',$q);
but I'm not sure what I'm doing wrong because none of the PHP sites that explain the functions, include an example of every character to search for.
Note, I only want it to replace spaces, comma's ',' dashes '-', '!' with forward slashes and then another replace function to replace any '&' with 'and'.
Regular expression-free example:
$str = str_replace([' ', ',', '-', '!'], '/', '& String! - !');
$str = str_replace('&', 'and', $str);
echo $str;
Try this :
$q = preg_replace('/[\s,\-!]/', '/', $q);
$q = str_replace("&","and",$q);
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