Hyvor Developer
  Home   Download   Copy
Code
<?php
$str = 'She had stood between the pack of wild dogs and what they wanted';
if (preg_match('/\bdogs\b/i', $str)) {
	echo 'Word dogs was found';
} else {
	echo 'Word dogs was not found';
}

echo "<br>"; // line break

// hotdogs will not match for dogs, because regex matches for word boundaries (\b)
$str = 'Linda returned with two hotdogs and handed one to each of them';
if (preg_match('/\bdogs\b/i', $str)) {
	echo 'Word dogs was found';
} else {
	echo 'Word dogs was not found';
}
Result