dsh7623 2013-05-26 04:56
浏览 234
已采纳

php数组使用if语句

why I do not get printed "11111111111"? I am parsing asterisk ami output.

foreach($pieces as $val)
{
$pieces1 = explode("
", $val);
echo ("$pieces1[0]
");
  if("$pieces1[0]" == "Response: Goodbye"){
    echo("11111111111");
  }
}
}
Asterisk Call Manager/1.1
Event: FullyBooted
Response: Success
Event: CoreShowChannel
Event: CoreShowChannel
Event: CoreShowChannelsComplete
Response: Goodbye
  • 写回答

2条回答 默认 最新

  • doumu5934 2013-05-26 04:58
    关注

    Most probably the input is CRLF-separated, not LF. Trim your exploded string of stray whitespace-like characters by changing it to:

    $pieces1 = array_map('trim', explode("
    ", $val));
    

    To properly debug issues like this always output debug data in a <pre> field, and embed it in apostrophes or double quotes so you actually see stuff like this - in HTML all whitespace normally collapses so you don't notice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部