日期:2014-05-17 浏览次数:20418 次
$content = "ab<meta http-equiv='Content-Type' content='text/html; charset=gbk'>b";//模拟html代码中的<meta> //preg_match('/<meta([^>]+)charset=[a-zA-Z-0-9]+([\'"])>/i',$content,$matches); //var_dump($matches);//此句说明可以匹配到 preg_replace('/<meta([^>]+)charset=[a-zA-Z-0-9]+([\'"])>/i',"<meta\\1charset=big5\\2>",$content); echo $content; //输出abb,也就是说替换不成功,将匹配部分替换为了空
$content = preg_replace('/<meta([^>]+)charset=[a-zA-Z-0-9]+([\'"])>/i',"<meta\\1charset=big5\\2>",$content); echo '<pre>'; echo $content;