如何使用preg_match从以下脚本中检索链接位置
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="www.example.com">here</a>.</h2>
</body></html>
谢谢
首先:如果您使用的是 CURL,请使用
<?php
// ....
curl_setopt($ch,CURLOPT_FOLLOWLOCATION)
?>
还
位置位于标题"位置:http.."
尝试通过get_headers获取标头或者通过这个模式解析这个输出,
$pattern = 'href='"(?<url>['"]+)'"'
如果我
理解正确,您只想从您的 html 代码中提取 url?如果是这样,您可以这样做:
preg_match('/object moved to <a href="(.+?)"> here/,$html_text,$match');
$url = $match[1];