我有这么一段代码
<td align=right>
<a href=http://www.sodu.org/>第一页</a> <a href=http://www.sodu.org/index_2.html>上一页</a> <a href=http://www.sodu.org/index_4.html>下一页</a>代码里也有可能没有 “<a href=http://www.sodu.org/index_2.html>上一页</a> ”
这一段现在我只想取出 下一页的url地址这个正则这么写
<td align=right>
<a href=http://www.sodu.org/>第一页</a> <a href=http://www.sodu.org/index_2.html>上一页</a> <a href=http://www.sodu.org/index_4.html>下一页</a>代码里也有可能没有 “<a href=http://www.sodu.org/index_2.html>上一页</a> ”
这一段现在我只想取出 下一页的url地址这个正则这么写
$str = <<<HT
<td align=right>
<a href=http://www.sodu.org/>第一页</a> & nbsp; <a href=http://www.sodu.org/index_2.html>上一页</a> & nbsp; <a href=http://www.sodu.org/index_4.html>下一页</a>
HT;
preg_match_all('/<a[^>]*href=([^>]*)>下一页<\/a>/is', $str, $matches);
print_r($matches[1]);
?>
<td align=right>
<a href=http://www.sodu.org/>第一页</a> <a href=http://www.sodu.org/index_2.html>上一页</a> <a href=http://www.sodu.org/index_4.html>下一页</a>
s;preg_match('/.*<a href=(.*)>下一页<\/a>.*/', $s, $arr);echo $arr[1];
preg_match('/\<a href=(.*)[/s]*\>下一页\<\/a\>/U', $s, $arr);
/\<a.+?href=[\'\"\s]*(.*)[\'\"\s]*\>下一页\<\/a\>/Ui
$str = <<<HT
<td align=right>
<a href=http://www.sodu.org/>第一页</a> & nbsp; <a href=http://www.sodu.org/index_2.html>上一页</a> & nbsp; <a href=http://www.sodu.org/index_4.html>下一页</a>
HT;
preg_match_all('/\<a.+?href=[\'\"\s]*(.*)[\'\"\s]*\>下一页\<\/a\>/Ui', $str, $matches);
print_r($matches[1]);
var_dump($data);要注意编码。
程序文件的编码和字符串的编码不一致也取不出来。因为里面有中文
我想了一下还是不用这种方法了,中间有中文不太好弄,如果编码错误就麻烦了我是将几个<a>链接里的地址都取出来,然后直接取最后的地址就出来了虽然麻烦点,但是保险呵呵,谢谢大家的帮忙了。结贴,给分了