How to retrieve number using regex and preg_match in php
I am trying to retrieve the ten digit id number from a textarea.
e.g id no 1234567890
I was trying to use.
preg_match("/('/^[0-9]{10}/')/", $article, $tags);
But it does not work. I 开发者_开发技巧appreciate any help.
Thanks.
Try:
preg_match_all("/\d{10}/", $article, $tags);
preg_match('/[0-9]{10}/', $article, $tags);
Try that. Or if you have multiple IDs, you can use preg_match_all
.
preg_match_all('/[0-9]{10}/', $article, $tags);
精彩评论