0

I need to filter the_content/the_excerpt and search & replace the following prepared array:

$searchArray = array("foo", "bar", "foo bar", ...);

My problem is the fact, that using php's str_replace() function it doesn't replace trailing strings like "foo bar". Instead it replaces only the "foo" without checking for the "foo bar" to be replaced. I understand why but I'm not sure how to solve this?

$content = str_replace(array_keys($searchArray), $replaceArray, $content);

add_filter('the_content', 'my_search_and_replace_function');
  • How does this require WordPress knowledge? I can see this as a pure PHP array/string manipulation problem ( namely one of search term order ) – Tom J Nowell Aug 17 '14 at 20:54
  • True it could be a PHP problem. I'm simply using it within WordPress and that's why I created my question here... – flowdee Aug 17 '14 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.