I have the following PHP code which creates a class to display a category name in lowercase and removes spaces with a hyphen. The issue i have is that some categories have an “&” in, for example: “sports-&-recreation”.
Is there a way I can replace the “&” with the word “and” so it appears “sports-and-recreation”?
What about looking at the documentation for the str_replace() function? You could pass in arrays, or just call the function twice, but you can’t just add a couple of extra parameters as you have done.
The str_replace function will take arrays as parameters, that’s how you get multiple values for search and replace. You can’t add more parameters like that.
Not exactly what I had in mind.
The main point of arrays is that they can hold a number of different values.
Using single values there is no need to make them arrays.
The square brackets [, int &$count ] mean the parameter is optional. The other 3 are not optional and there are only 3 of them.
What mixed means in mixed $search , mixed $replace , mixed $subject is not so clear, but some clue is under “Parameters”. The documentation has “value … an array may be used” but might be clearer if it were “string value … an array of string values may be used” instead.
What the last “mixed” means is
Return Values
This function returns a string or an array with the replaced values.
There are several examples under, errmm, Examples that should help you see how you should code what you want.