PHP combines regular get number in string
<?php
$patterns = "/\d+/";//First type
//$patterns = "/\d/"; The second kind of
$strs = "left:0px;top:202px;width:90px;height:30px";
Preg_match_all ($patterns, $strs, $arr);
Print_r ($arr);
/*************** Run result *********************/
//First
array
(
[0] => array
(
[0] => 0
[1] =>
[2] =>
[3] =>)
)
//second
array
(
[0] => array
(
[0] => 0
[1] => 2
[2] => 0
[3] => 2
[4] => 9
[5] => 0
[6] => 3
[7] => 0
)
)
PHP gets the number of the specified string $a = "123 of times 12345678 occur"; Give a function to crawl to the number 12345678 in $a, if not, then return 0
To write a good function,
1. Match only digits of length 8
2. If found, return to change the number, if not then return 0
function A ($STR) {return
Preg_match ('/([0-9]{8})/', $STR, $a)? $a [1]: 0;
}
Search on the Internet to this test can also be found, but if the character length is not d{4} indefinite length is not
function FindNum ($str = ') {
if (empty ($STR)) {return ';}
$reg = '/(\d{4} (\.\d+)?) /is ';//matching number of regular expression
Preg_match_all ($reg, $str, $result);
if (Is_array ($result) &&!empty ($result) &&!empty ($result [1]) &&!empty ($result [1][0])) { return
$result [1][0];
}
return ';
}
And then I found out that there was a
$str =trim ($STR);
if (Preg_match (' | \d+) | ', $STR, $r)] return $r [1];
Found that this can get any number of consecutive lengths, of course, also see a lot of online, but there is a can, so there is no more testing.
The above mentioned is the entire content of this article, I hope you can enjoy.