PHP函数判断网页标题中是否包含特定汉子字符!
<?php
function file_title_exists($url) {
$lines_array = file($url);
$lines_string = implode('', $lines_array);
preg_match('/<title>(.*)<\/title>/i', $lines_string, $title);
$strtitle = implode($title);
echo $strtitle;
$strpos="信息提示";
if( strpos($strtitle,$strpos)>0 )
{
echo "included";
}
else
{
echo "not included";
}
//echo $title[1];
}
$url = 'http://zhidao.baidu.com/question/1111728147653908939.html';//不存在
file_title_exists($url);
重要提示:
这个PHP文件的保存一定要是“ANSI”格式,通过文本编辑器另存之后才能使用,否则,因为会因为汉字乱码问题把函数搞得一团糟不可用,坑,老子在这里浪费了半天时间,Shit!