How to match a part of an <iframe> tag?

后端 未结 6 2027
小鲜肉
小鲜肉 2021-01-21 13:48

I\'m trying to match the highlighted parts of this string:

 maybe something here src=\"http://some.random.url.com/\" and the string continues.         


        
6条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 13:58

    You should use a DOM parser, but this regex would get you started if there is a reason you must use regexes

    .*(?]*(?src=['"][^>'"]+['"]?).*
    

    It uses named capture groups by the way, here's how they work

    preg_match('/.*(?]*src=[\'"](?[^>\'"])+[\'"]?.*/', $searchText, $groups);
    print_r($groups['iframeSrc']);
    

提交回复
热议问题