So i am trying to replace spaces and forward slashes in a url with a hyphen. Say we have a website named: www.example.com/car/bmw/porsche where bmw/porsche is one value
I can seem to get it to work for a space but having trouble with the forward slash. This is what i have for the space (yes i know the search and replace are at opposite ends but it seems to work and doesn't work if i swap them round)
$name = str_replace("-", " ", $request[2]);
$id = $category->find_id_by_name($name);
I tried a number of ways to make it work but it still doesn't seem to want to listen.. these are the ways i have tried but neither work:
1.
$name = str_replace("-", array(" ", "/"), $request[2]);
$id = $category->find_id_by_name($name);
2.
$chars = array(" ", "/");
$name = str_replace("-", $chars, $request[2]);
$id = $category->find_id_by_name($name);
Both which produce the error:- Notice: Array to string conversion
3.
$name = str_replace(array("-","//"), " ", $request[2]);
$id = $category->find_id_by_name($name);
In the above code, space works but not the forward slash. Tried changing the forward slash to a single one, single quotes with both one and two slashes but still nothing. I have spent a good couple of hours fiddling around with it but nothing seems to work