Forum Moderators: coopster
As a newbie to PHP, can someone please help me with a frustrating small problem that has defeated my searches of the PHP manual.
I want to search a string of text for the occurrence of a certain word or set of words. Easy enough, but I only want to find occurences of whole words. For example, if I'm searching for "today's exam", I want to ignore "today's example".
Any thoughts please?
here's what you're looking for:
from : [php.net...]
<?php
/* The \b in the pattern indicates a word boundary, so only the distinct
* word "web" is matched, and not a word partial like "webbing" or "cobweb" */
if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
if (preg_match("/\bweb\b/i", "PHP is the website scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
?>