preg_match数字? [英] preg_match digits?

查看:102
本文介绍了preg_match数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



字符串中提取前两位数的最有效方法是什么?


以下是错误的,因为它只给出了我是第一个

两位数的实例:

$ string = ujdk3ca94abc

preg_match(" / \d { 2} /,$ string,$ result);

echo" $ result [0]";

//打印94.但是,结果我我要找的是39


这是另一个例子:

$ string =''abc 8a bc abc934'';

//期望的结果= 89


谢谢。

What is the most efficient way of extracting the first two digits in a
string?

The following is wrong for me, because it only gives me the first
instance of two digits together:

$string = ujdk3ca94abc
preg_match("/\d{2}/",$string,$result);
echo "$result[0]";
//prints 94. However, the result I am looking for is 39

Here''s another example:
$string = ''abc 8a bc abc934'';
//desired result = 89

Thank you.

推荐答案

string = ujdk3ca94abc

preg_match(" / \d {2} /",
string = ujdk3ca94abc
preg_match("/\d{2}/",


string,


result) ;

echo"
result);
echo "


这篇关于preg_match数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆