我只想保留数字并从变量中删除所有字符。
例如:
input: +012-(34).56.(ASD)+:"{}|78*9
output: 0123456789
最佳答案
这是一般的做法:
$numbers = preg_replace('/[^0-9]+/', '', '+012-(34).56.(ASD)+:"{}|78*9');
echo $numbers;
输出:
0123456789
关于PHP/Zend : How to remove all chars from a string and keep only numbers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2635781/