Home > Article > Backend Development > 求正则表达式啊。难啊
$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);
$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 = '
PHP code?12345678910$content = '
$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]);
引用 1 楼 yangball 的回复:PHP code?12345678910$content = '
preg_match_all('/href=[\'"]?([^>]*&toc=[^\'">]*)/is', $content, $m);print_r($m[1]);//有问题直接发帖就行了,这里挺多热心人和高手的。