我可以为了用什么模式来获得整数值 - 从> 1:preg_match_all - 正规表达式模式
$digit = 'My messages (1 new)';
$pattern = '/^My messages ([\d]+) ([\w]+)/i';
preg_match_all($pattern, $digit, $match);
纠正我的代码,请。在此先感谢
我可以为了用什么模式来获得整数值 - 从> 1:preg_match_all - 正规表达式模式
$digit = 'My messages (1 new)';
$pattern = '/^My messages ([\d]+) ([\w]+)/i';
preg_match_all($pattern, $digit, $match);
纠正我的代码,请。在此先感谢
你可以尝试
$digit = 'My messages (1 new)';
$pattern = '/\d+/';
preg_match_all($pattern, $digit, $match);
有用的链接学习正则表达式
$pattern = "/^My messages \((\d+) (\w+)\)/i';
这应该工作:
$digit = 'My messages (1 new)';
$pattern = '/\d+/';
preg_match_all($pattern, $digit, $match);
仅供参考,这将只匹配一个单一的数字 - 如果有10台新的消息,它只会匹配“1”。此外,由于数字没有任何大小写,因此/ i是不必要的。 – pgl 2011-12-14 10:00:13
也许/ \ d + /会更好?以防万一他们有超过9条新消息。 – 2011-12-14 10:00:36