dongxuan2577 2014-05-29 07:36
浏览 43
已采纳

如何从字符串数组中删除错误的符号和错误的长度字符串?

I have such array:

$array = array('abC12', 'bC44', 'Am286c$', 'cC092', 'cC09288');

With using rexexp it is necessary to, at first, delete symbols (replace by ''), that are not in [A-Ca-c0-9]. At second, it is necessary to delete from array variables that not match such condition: string length not equal to 5 (values 'bC44' and 'cC09288').

So, as result array must contain:

$array = array('abC12', 'A286c', 'cC092');

Thanks you for any help!

Vladimir.

  • 写回答

2条回答 默认 最新

  • donglan8870 2014-05-29 07:42
    关注
    $result = array();
    foreach ($array as $val) {
        $val = preg_replace('/[^a-c0-9]/i', '', $val); // Remove symbols
        if (strlen($val) == 5) { // Check string length
            $result[] = $val;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了