dongzhouzhang8696 2013-09-25 15:56
浏览 33
已采纳

用于Sendy API的PHP Foreach关联数组循环

I always struggle with loops and in particular associative arrays is still new to me and trying to get past it. I am trying to setup a form to insert multiple emails at once into our sendy email list through the use of their api. I am successful in inserting the first email into the list, but the remaining emails get lost. Your help is greatly appreciated!

PHP Below:

<?php 
require('sendyLibrary.php');
$sendy = new SendyLibrary('3');
$email = $_POST['email'];

//$textareaContents = str_replace("", ',', $email);
$multipleEmails = explode("", $email);
foreach($multipleEmails as $key => $finalEmail) {
    $sendy->subscribe(array(
        'email' => $finalEmail
    ));
    echo 'email: ' . $finalEmail .'<br/>';
}?>

Response from POST method:

email   sam@testing.com samg@testing.com samgo@testing.com samgol@testing.com samgolu@testing.com

Source from POST method:

email=sam%40testing.com%0D%0Asamg%40testing.com%0D%0Asamgo%40testing.com%0D%0Asamgol%40testing.com%0D%0Asamgolu%40testing.com

Thank you for your help!

  • 写回答

1条回答 默认 最新

  • duanjie6912 2013-09-25 16:07
    关注

    There is actually a inbetween all of the emails. I assume the subscribe method is throwing them out because when you explode the array on then you will have new lines on all the remaining emails. Looking like:

    array("email1@testing.com", 
          "
    email2@testing.com", 
          "
    email3@testing.com");
    

    You should explode the tring on like so:

    $multipleEmails = explode("
    ", $email);
    

    The other option would be to fix the code that sends the POST to provide a better delimited string..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集