从字符串中提取数字 [英] Extract numbers from a string

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

问题描述

我想从包含数字和字母的字符串中提取数字:

I want to extract the numbers from a string that contains numbers and letters like:

"In My Cart : 11 items"

我想在这里获取电话号码11或其他任何电话号码.

I want here to get the number 11 or any other number.

推荐答案

$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);

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

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