So I have str_replace which searches a string for "and" and replaces it with &
However if there is a word which contains the letters "and" for example, "Howland" it will replace it with Howl&
.
How can I make it so that it only searches for the word and.
This is my function I have setup:
function add_ampersand( $string ) {
$string = str_replace( 'and', '&', $string );
return $string;
}
I must note that this function is being used in a URL so the "and" will contain "-" next to either side of it, which then gets converted into spaces.