meh*_*mpt 8 php string numbers
假设,我有这个字符串:
$string = "Hello! 123 How Are You? 456";
Run Code Online (Sandbox Code Playgroud)
我想将变量设置$int为$int = 123456;
我该怎么做?
例2:
$string = "12,456";
Run Code Online (Sandbox Code Playgroud)
需要:
$num = 12456;
Run Code Online (Sandbox Code Playgroud)
谢谢!
Iły*_*sov 29
正确的变体将是:
$string = "Hello! 123 How Are You? 456";
$int = intval(preg_replace('/[^0-9]+/', '', $string), 10);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
49269 次 |
| 最近记录: |