$result = file_get_contents('https://website.net');
$regex = '/< *img[^>]*src *= *["\']?([^"\']*)/i';
preg_match_all($regex, $result, $matches)
return($matches[1][1]);
图像src,我想在URL中三次返回countains“ amp”,像这样:“ https://abcAMPabcAMPabcAMP.com/image.jpeg”我只想返回“ https://abcabcabc.com/image.jpeg而没有所有” amp“怎么办?我认为我应该使用str_replace,但我不知道如何将其与return()一起使用。
如果“ AMP”区分大小写:
return str_replace('AMP', '', $matches[1][1]);
否则:
return str_ireplace('AMP', '', $matches[1][1]);