Hi
I'm a bit of a beginner when it comes to PHP, but am modifying a 3rd party script - but am having a problem.
Basically I want the script to rewrite certain words before publishing them on the website.
i.e.
$phrase = "$article[description]";
$find_replace = array(
"black" => "red",
"blue" => "green"
);
$oldWord = array_keys($find_replace);
$newWord = array_values($find_replace);
$article[description2] = str_replace( $oldWord, $newWord, $phrase );
This works fine - However I only want it to replace the first instance of the word - leaving the rest as they were - so I've tried using preg_replace instead of str_replace - but it then just displays no article at all on the website.
i.e.
$article[description2] = preg_replace( $oldWord, $newWord, $phrase, 1 );
Tried loads of variations but it doesn't seem to want to work - Any ideas on what I'm doing wrong?
Thanks in advance, much appreciated.