duanpo2037 2018-02-28 10:27
浏览 14
已采纳

PHP爆炸无法正常使用逗号[关闭]

Why this code isn't working properly? The string should be divided by commas but it looks like it's divided by commas and spaces at the same time (or something like that).

// example $str
$str = 'Test Tset <test@test.com>, Foo Abc <foo@abc.com>, Another Email <anotheremail@mail.test>, email_wo_brackets@gmail.com';

$emails = [];
$email_list = explode(',', $str);

foreach ($email_list as $email) {
    if (!in_array($email, $emails) and strpos($email, '@') !== false) {
        $emails[] = $email;
        echo sizeof($emails) . " $email<br>";
    }
}

It should be:

1 Test Tset <test@test.com>
2 Foo Abc <foo@abc.com>
3 Another Email <anotheremail@mail.test>
4 email_wo_brackets@gmail.com

But it's:

1 Test Tset 
2 Foo Abc 
3 Another Email 
4 email_wo_brackets@gmail.com
  • 写回答

1条回答 默认 最新

  • dreamlife2014 2018-02-28 10:32
    关注

    Ah I fixed it already. The problem was in "<" formatting.

    $email = str_replace(['<', '>'], '%%', $email);
    

    EDIT:

    $email = htmlspecialchars($email);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP