1. Home
  2. Computing & Technology
  3. PHP / MySQL
photo of Angela Bradley

Angela's PHP / MySQL Blog

By Angela Bradley, About.com Guide to PHP / MySQL

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.";
if (preg_match("/bacon/", $data))
{
echo "You had bacon.";
}
else
{
echo "You had did not have bacon.";
}

Here we simply check if the existence of the word 'bacon' is true of false, and echo the output accordingly.

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL

©2008 About.com, a part of The New York Times Company.

All rights reserved.