【发布时间】:2012-04-14 13:43:09
【问题描述】:
这是一个例子:
来源网址是http://www.vietbando.com/maps/#t=1&sk=258+lý+Thường+Kiệt
当我发布表单时。
它变成这样的新网址
http://www.vietbando.com/maps/#t=1&sk=258+lý+Thường+Kiệt&l=4&kv=15.0132985,106.744091
如何获取新的网址?
【问题讨论】:
这是一个例子:
来源网址是http://www.vietbando.com/maps/#t=1&sk=258+lý+Thường+Kiệt
当我发布表单时。
它变成这样的新网址
http://www.vietbando.com/maps/#t=1&sk=258+lý+Thường+Kiệt&l=4&kv=15.0132985,106.744091
如何获取新的网址?
【问题讨论】:
【讨论】:
在这种情况下,您可以解析响应的标题以获取 url。 您必须使用此代码来执行此操作:
$ch_url = curl_init();
curl_setopt($ch_url, CURLOPT_URL, 'http://www.example.com/)'; //your first url
curl_setopt($ch_url, CURLOPT_USERAGENT, 'AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5');
curl_setopt($ch_url, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_url, CURLOPT_HEADER, 1);
curl_setopt($ch_url, CURLOPT_NOBODY, 1); //we don't need to recieve the body of response
$headers = curl_exec($ch_url);
curl_close ($ch_url);
$pattern = '`.*?((http)://[\w#$&+,\/:;=?@.-]+)[^\w#$&+,\/:;=?@.-]*?`i'; //this regexp finds your url
if (preg_match_all($pattern,$headers,$matches))
$url = $matches[1][0]; //your second url
【讨论】:
.*?((http)://[\w#$&+,\/:;=?@.-]+)[^\w#$&+,\/:;=?@.-]*?i'; //这个正则表达式找到你的网址 if (preg_match_all($pattern,$headers,$matches)){ $url = $matches[1][0]; //你的第二个网址 echo $url; }