diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
If you only want to know if the word is there, and not need its position, then preg_match() will do the trick.
if (preg_match('%\b(word|wordtwo|wordthree)\b%i', $text) > 0) {
// one of the words was found
}
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
As Prit (+1 for his suggestion!) states preg_match could be a cooler solution. strpos() is quicker, BUT looping strpos vs. preg_match would probably be slower.
For an array of values:
$wordarray = array('check','cheque','czech');
$pattern = implode("|",$wordarray);
if (preg_match("/($pattern)/", $text)){
echo "Word is not found";
}else{
echo"Word is not found";
}
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080