<?php
//模式分隔符后的"i"标记这是一个大小写不敏感的搜索
if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
?>
Example #2 查找单词"word"
<?php
/* 模式中的标记一个单词边界, 所以只有独立的单词"web"会被匹配, 而不会匹配
* 单词的部分内容比如"webbing" 或 "cobweb" */
if (preg_match("/web/i", "PHP is the web scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
if (preg_match("/web/i", "PHP is the website scripting language of choice.")) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
?>