True or False with Preg_match
Monday June 12, 2006
The PHP function preg_match is used to search a string of data until it finds the specified search string. Because it is either returning a 1 (true) or a 0 (false) it is often used as part of a conditional statement.
$data = "I had a waffles for breakfast today.";Here we simply check if the existence of the word 'bacon' is true of false, and echo the output accordingly.
if (preg_match("/bacon/", $data))
{
echo "You had bacon.";
}
else
{
echo "You had did not have bacon.";
}


No comments yet. Leave a Comment