I have a query with a loop that has a lot of keywords that need to be linked to other sites. I understand that using str_replace can replace one string term with other information like so:
how do I go about changing more than one term? I.E., besides the above string being changed to a link, I have others such as “Special Events” that has an external link to a different page that’s coming from the same query.
I’ve thought about AND/OR, but it wasn’t working. Any suggestions?
$input = "A and B went shopping.";
$search = array("A", "B");
$replace = array("Alice", "Bob");
$output = str_replace($search, $replace, $input);
echo $output; // Outputs "Alice and Bob went shopping."
variable $text is the content queried from database
variable $search is an array search for these specific terms
variable $replace is another array to replace the $search array terms
$output is to $search and $replace the terms in the $text variable
$after replaces any <br />s with paragraph marks in the $text variable
$after gets echoed
I’m assuming that after the series of instruction is completed that $after would be echoing all information (including the search and replace) accordingly. Did I forget something?