Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个字符串
$var = "adf91uaj19jj99877ad009";
从这个变量中获取所有整数并创建一个新整数的最简单方法是什么?在这种情况下
$newVar="911999877009";
就像用大锤敲钉子一样。将所有非数字字符 ( \D) 替换为空 ( '')。
\D
''
$newVar = preg_replace('/\D/', '', $var);
你可以试试
$var = "adf91uaj19jj99877ad009"; $var = filter_var($var,FILTER_SANITIZE_NUMBER_INT);
输出
string '911999877009' (length=12)