stripping out all characters from a string, leaving numbers

ε祈祈猫儿з 提交于 2019-11-28 09:03:03
$str = preg_replace('/[^0-9.]+/', '', $str);

replace substrings that do not consist of digits or . with nothing.

preg_replace('/[^0-9.]/', '', $string);
Juraj Blahunka
$input = 'some str1ng 234';
$newString = preg_replace("/[^0-9.]/", '', $input);
Veger

To satisfy my curiosity I asked about the speed of the proposed answers and as shown in preg_replace speed optimisation/ it is (much) faster to use str_replace() than preg_replace().

So you might want to use str_replace() instead.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!