>  기사  >  백엔드 개발  >  求正则表达式啊。难啊

求正则表达式啊。难啊

WBOY
WBOY원래의
2016-06-23 14:04:121008검색

$content = '<td align="right">  <b>[1]</b>   <a href=Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=2>2</a>  <a href=Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=3>3</a><a href="Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=188">Last</a></td>'; $a = preg_match_all('/a href([\S])*/is', $content, $matches); print_r($matches);

各位大牛,请问有什么办法,可以用正则表达式,把pgno里面的数组搞出来吗
超链接 href最后那个&
跪求。


回复讨论(解决方案)

$content = '<td align="right">  <b>[1]</b>   <a href=Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=2>2</a>  <a href=Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=3>3</a><a href="Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=188">Last</a></td>';preg_match_all('/pgno=(\d+)/is', $content, $m);print_r($m[1]);/**Array ( [0] => 2 [1] => 3 [2] => 188 )*/

PHP code?12345678910$content = '

  [1]   
强,高手。谢谢。可以加个联系方式吗。有时候想问下,初学php的。

PHP code?12345678910$content = '

  [1]   
$content = '<td align="right">  <b>[1]</b>  <a href="www.baidu.com"/><a href="Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5"/><a href="Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&GetProducts=1"/> <a href=Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=2>2</a>  <a href=Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=3>3</a><a href="Store.aspx?SessionCode=58152D67C1C34905B5155F2FDE0B0DE5&toc=136337:770291^2^1|136337^0^752&GetProducts=1&SelectedAttributes=33111116327|741&PRL=1_232.22%257e588.14%257e%2524232.22%2b%2b-%2b%2b%2524588.14%2b(369)_2_588.69%257e729.2%257e%2524588.69%2b%2b-%2b%2b%2524729.20%2b(371)_3_729.99%257e879.64%257e%2524729.99%2b%2b-%2b%2b%2524879.64%2b(372)_4_880.85%257e1078.2467%257e%2524880.85%2b%2b-%2b%2b%25241%252c078.25%2b(369)_5_1079%257e1342.88%257e%25241%252c079.00%2b%2b-%2b%2b%25241%252c342.88%2b(370)_6_1343.28%257e1623.3%257e%25241%252c343.28%2b%2b-%2b%2b%25241%252c623.30%2b(369)_7_1623.66%257e1824.59%257e%25241%252c623.66%2b%2b-%2b%2b%25241%252c824.59%2b(369)_8_1825.2%257e2140.7%257e%25241%252c825.20%2b%2b-%2b%2b%25242%252c140.70%2b(369)_9_2142.24%257e2609.81%257e%25242%252c142.24%2b%2b-%2b%2b%25242%252c609.81%2b(370)_10_2613.21%257e31877.92%257e%25242%252c613.21%2b%2b-%2b%2b%252431%252c877.92%2b(349)&pgno=188">Last</a></td>'; preg_match_all('/pgno=(\d+)/is', $content, $m);print_r($m[1]);

请我还有办法可以获得整个页面里面 href 里面包含有toc查询的标签的 href吗
比如前面3个href就不包含toc,后面包含,怎么把后面的href弄出来呢。我高了一个晚上都没搞定。
谢谢您

引用 1 楼 yangball 的回复:PHP code?12345678910$content = '

 &nbsp;[1] &nbsp; 
preg_match_all('/href=[\'"]?([^>]*&toc=[^\'">]*)/is', $content, $m);print_r($m[1]);//有问题直接发帖就行了,这里挺多热心人和高手的。
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.