php 正则提取数字
Posted ec04
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 正则提取数字相关的知识,希望对你有一定的参考价值。
<?php
//$patterns = "/^(http|https):\/\/(.)*\.(.)*$/";
$patterns = "/\d+/";
$strs="23345swwyuiopbfASWEDD4667";
preg_match_all($patterns,$strs,$arr);
print_r($arr);
?>
Array
(
[0] => Array
(
[0] => 23345
[1] => 4667
)
)
<?php
//$patterns = "/^(http|https):\/\/(.)*\.(.)*$/";
$patterns = "/\d/";
$strs="23345swwyuiopbfASWEDD4667";
preg_match_all($patterns,$strs,$arr);
print_r($arr);
?>
Array
(
[0] => Array
(
[0] => 2
[1] => 3
[2] => 3
[3] => 4
[4] => 5
[5] => 4
[6] => 6
[7] => 6
[8] => 7
)
)
<?php
$str
=
"sssefss$2345.1234dddfffeds$456$00.23RR"
;
$pattern
=
‘/\$(\d+\.?\d+)/‘
;
if
(preg_match_all(
$pattern
,
$str
,
$match
)){
echo
‘<pre>‘
;
print_r(
$match
);
}
else
{
echo
‘没有找到!‘
;
}
结果:
Array
(
[0] => Array
(
[0] =>
$2345
.1234
[1] =>
$456
[2] =>
$00
.23
)
[1] => Array
(
[0] => 2345.1234
[1] => 456
[2] => 00.23
)
)
以上是关于php 正则提取数字的主要内容,如果未能解决你的问题,请参考以下文章