我正在修改一个脚本,从一长页文本输出字符串,这就像一个魅力,唯一的问题是,第二组将只输出数字。
<?php
$file = file_get_contents('page.htm');
preg_match_all('#<a.*?href="(?:http://)www.site.com/profiles/(?P<id>'d+)[^>]+#msi',$file, $matches);
$f = fopen("file.txt", "w");
print_r($matches['id']);
fwrite($f, print_r($matches['id'], true));
fclose($f);
echo "<br><br>";
preg_match_all('#<a.*?href="(?:http://)www.site.com/id/(?P<id2>'d+)[^>]+#msi',$file, $matches2);
$f = fopen("file.txt", "w");
print_r($matches2['id2']);
fwrite($f, print_r($matches2['id2'], true));
fclose($f);
?>
顶部的一个应该这样做,但底部的一个需要允许所有字符,包括特殊的,有没有什么缺失或我需要添加的东西?非常感谢!
我明白了。
改变'#<a.*?href="(?:http://)www.tf2items.com/id/(?P<id2>'w+)[^>]+#msi'
'#<a.*?href="(?:http://)www.tf2items.com/id/(?P<id2>'d+)[^>]+#msi'
显然'w只代表字母(wtf)而'd代表一切