需要从数组中删除所有字母数字字符 [英] Need to remove all AlphaNumeric characters from an array
本文介绍了需要从数组中删除所有字母数字字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的数组,我想去除所有字母字符。
I've an array like this ,i want to strip all alpha characters.
$testString = Array ([0] => 46_xsdfdsa_ddasdasd [1] => 23423_wrwerwer_ajbfdahbfkahflagassl);
echo preg_replace("/[^0-9,.]/", "", $testString);
输出应为46,23423。
Output should be 46,23423.
我在上面尝试,并没有工作。
I tried above and it did n't work.
感谢在前进
推荐答案
这应该工作:
echo preg_replace("/[a-zA-Z0-9]/", "", $testString);
仅供参考,字母数字表示字母+数字字符。从你的问题的标题,你似乎表明,要全部更换。让我们知道这对你的作品。
FYI, alphanumeric means alpha + numeric characters. From your question title, you seem to suggest that you want to replace them all. Let's know if this works for you.
如果在输出中,你只需要数字,,
,这是你会做什么:
If in the output you only want numbers, ,.
, this is what you would do:
echo preg_replace("/[^\d,.]/", "", $testString);
示例:
$str = '23,423_.wrwerwer_ajbfdahbfkahflagassl';
echo preg_replace("/[^\d]/", "", $str); // result: 23,423.
这篇关于需要从数组中删除所有字母数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文