语法regex用于提取图像的源

0 php regex

啊啊啊!

我不能"猜测"我应该使用巫婆语法来提取图像的来源,而只是提取网址而src=不是引号?

这是我的一段代码:

function get_all_images_src() {
    $content = get_the_content();
    preg_match_all('|src="(.*?)"|i', $content, $matches, PREG_SET_ORDER);
    foreach($matches as $path) {
        echo $path[0];
    }
}
Run Code Online (Sandbox Code Playgroud)

当我使用它时,我打印出来:

src="http://project.bechade.fr/wp-content/uploads/2009/09/mer-300x225.jpg"
Run Code Online (Sandbox Code Playgroud)

我希望只得到这个:

http://project.bechade.fr/wp-content/uploads/2009/09/mer-300x225.jpg
Run Code Online (Sandbox Code Playgroud)

任何的想法?

谢谢你的帮助.

Bar*_*ers 5

不完全是你问题的答案,但在解析html时,请考虑使用正确的html解析器:

foreach($html->find('img') as $element) {
  echo $element->src . '<br />';
}
Run Code Online (Sandbox Code Playgroud)

请参阅:http://simplehtmldom.sourceforge.net/