我有一个包含iframe的字符串
<iframe width="560" height="315" src="https://www.test.com/" title="test" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
如何使用preg_replace提取包含它的链接;我必须提取以下链接'https://www.test.com/‘
通过清除iframe标记中的字符串很明显
//我解决了这个问题
$stringaiframe = 'test inserisco ifram tag <iframe width="560" height="315" src="https://www.test.com/" title="test" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
$stringaiframe = preg_replace('/<iframe\s+.*?\s+src=("[^"]+").*?<\/iframe>/', '""""""$1""""""', $stringaiframe);发布于 2021-10-09 14:48:15
我会和stripos商量一下。找到字符串‘src=’的第一个匹配项,然后找到'"‘的第一个匹配项。中间是你的URL。
发布于 2021-10-09 14:58:48
您可以简单地拆分此字符串。
var str = '<iframe width="560" height="315" src="https://www.test.com/" title="test" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
var src = str.split('src=')[1].split(/[ >]/)[0];
alert("source ===>" + src)如果你想在中更新,请使用这个脚本。
$str = '<iframe width="560" height="315" src="https://www.test.com/" title="test" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
preg_match('/src="([^"]+)"/', $str, $match);
$url = $match[1];此脚本将为您提供iframe的src。请查看并让我知道
https://stackoverflow.com/questions/69507738
复制相似问题