本文实例讲述了PHP正则匹配操作。分享给大家供大家参考,具体如下:
$str = <<< EOT
幸福领地
一世情长
EOT;
if(preg_match_all("%
(.*?)%si", $str, $matches)) {$arr[0][] = $matches[1];
}
if(preg_match_all("/src="([^/i", $str, $matches)) {
$arr[1][] = $matches[1];
}
print_r($arr);
exit;
?>
运行结果如下:
Array
(
[0] => Array
(
[0] => Array
(
[0] => 幸福领地
[1] => 一世情长
)
)
[1] => Array
(
[0] => Array
(
[0] => http://www/template9/yunqingjian/jianjie/68.jpg
[1] => http://www/template9/yunqingjian/jianjie/69.jpg
)
)
)
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:http://tools.jb51.net/regex/create_reg
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php正则表达式用法总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。