首页 > 后端开发 > php教程 > 求正则表达式啊。难啊

求正则表达式啊。难啊

WBOY
发布: 2016-06-23 14:04:12
原创
1026 人浏览过

$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;

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板