preg_match_all , get all img tag that include a string

不打扰是莪最后的温柔 提交于 2019-12-04 13:06:54

I'd have to go with this one:

/(<img[^>]*src=".*?(?:pre\.gif|next\.gif)"[^>]*>)/i

Or in PHP:

$regexp = '/(<img[^>]*src=".*?(?:pre\.gif|next\.gif)"[^>]*>)/i';
$iResults = preg_match_all($regexp, $str, $aMatches);
print_r($aMatches); // you'll see what you need

-- edit: Oops. I made a mistake. The . in pre.gif and next.gif in the regexp the regexp must be escaped!! I didn't before. -- edit

PS. You might be using preg_match_all wrong. The arguments are: (pattern, subject, &matches)

PS. The results of my pattern + your subject:

Array
(
    [0] => Array
        (
            [0] => <img border="0" alt="icon" src="http://www.site.com/images/pre.gif" width="90" height="v">
            [1] => <img border="0" alt="icon" src="http://www.site.com/images/next.gif" width="90" height="90">
        )
    [1] => Array
        (
            [0] => <img border="0" alt="icon" src="http://www.site.com/images/pre.gif" width="90" height="v">
            [1] => <img border="0" alt="icon" src="http://www.site.com/images/next.gif" width="90" height="90">
        )
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!