模板解析时候遇到的正则 \x7f-\xff
ASCII 码查询
http://jingyan.baidu.com/article/ed2a5d1f5616aa09f7be1761.html
http://www.asciima.com/
当?该字符在* ,+,?,{n},{n,}后面时,匹配模式是非贪婪的,默认的为贪婪模式。
向后引用 http://www.jb51.net/article/27790.htm
项目中需要将一条新闻内容中所有嵌入的图片找出来。这时当然用正则 使用preg_match_all()函数。
刚开始是这样写的:
if($pid == 7){ preg_match_all('/<img.*src=[\"]?(.*?)[\"]?\s.*?>/i',$row["post_content"],$matches); $data["list"][$key]["photos"] = $matches[1]; }else{ $data["list"][$key]["photos"] = ""; }
其中
$matches[1]是匹配正则表达式第一个括号的内容,即想要的图片路径。结果一个匹配项总是含有多个img标签。
if($pid == 7){ preg_match_all('/<img.*?src=[\"]{1}(.*?)[\"]{1}\s.*?>/i',$row["post_content"],$matches); $data["list"][$key]["photos"] = $matches[1]; }else{ $data["list"][$key]["photos"] = "";最后发现少了一个<img.*?,由贪婪模式变成非贪婪模式 }
preg_match_all('/<{1}img\s*?src=[\"]{1}(.*?)[\"]{1}[^>]*?>{1}/i', $row["post_content"], $matches);