How to retrieve link location using preg_match in PHP
How to retrieve link location from following script using preg_match
<html><head><title>Object moved</title></head><body>
<h2>Object moved to &l开发者_JAVA技巧t;a href="www.example.com">here</a>.</h2>
</body></html>
Thanks
First: if you are using CURL use
<?php
// ....
curl_setopt($ch,CURLOPT_FOLLOWLOCATION)
?>
else
Location is in header "Location:http.."
try to get headers by get_headers or parse this output by this pattern ,
$pattern = 'href=\"(?<url>[\"]+)\"'
If I understood it correctly, you simply want to extract the url, from your html code? If so, you can do it like this:
preg_match('/object moved to <a href="(.+?)"> here/,$html_text,$match');
$url = $match[1];
精彩评论