【发布时间】:2011-07-03 09:55:08
【问题描述】:
我有一个小问题,因为我的 preg_match_all 运行不正常。
我想要做的是从 wordpress 中提取 post_content 中 all the images 的 src 参数,这是一个字符串 - 不是完整的 html 文档/DOM(因此不能使用文档解析器功能)
我目前正在使用下面的代码,不幸的是它太不整洁并且只适用于 1 个图像 src,我想要来自该字符串的所有图像源
preg_match_all( '/src="([^"]*)"/', $search->post_content, $matches);
if ( isset( $matches ) )
{
foreach ($matches as $match)
{
if(strpos($match[0], "src")!==false)
{
$res = explode("\"", $match[0]);
echo $res[1];
}
}
}
有人可以帮忙吗...
【问题讨论】:
-
我们可以将 $search->post_content 作为包含单个或多个图像标签的任何字符串
标签: php wordpress preg-match-all