I saw your question earlier but didn't get a chance to reply...seems like Vincent has already done so but here's what I've got...I've not used the PERL-compatible regular expression functions preg_match() and preg_replace() because I'm not familiar with Perl and it's syntax (and I don't know what you are trying to match and replace), instead I've used their equivalents eregi() and eregi_replace(), both of which run a case-insensitive pattern search (unlike their PCRE counterparts mentioned above). I did not read your question properly and I'm afraid I only wrote a function that searches for several words in one string ( Sorry!!🙁 )
<?
function findreplace($word,$newword,$string){
//pass the elements of the $word array into a new variable $eachword
for ($i=0; $i<count($word); $i++){
$eachword=$word[$i];
//test to see if the word exist in the string
if (eregi(" $eachword ", $string)){
//there is a match, print confirmation statement
echo "$eachword was found in string.<BR>";
//replace it with new word
$new_string=eregi_replace(" $eachword ", " $newword ", $string);
//print new string
echo "New string:<BR>$new_string<BR>";
} else {
//no match, print statement to say so
echo "$eachword NOT found.<BR>";
}
}
}
//To find the following words
$word=array("abjured","repudiated");
//and replace it with a new word
$newword="renounced";
//in the following string
$string="His family disowned him because he abjured his religion";
findreplace($word,$newword,$string);
?>
In order to do what you are looking for...that is search for several words in several variables/strings, I suggest containing the variables in an array and cycling them with a "for" loop, each time testing for the words you are looking for.
I hope this helps. If you have any other questions, please don't hesitate to ask.
Allen