0

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

foreach($pieces as $val)
{
$pieces1 = explode("\n", $val);
echo ("$pieces1[0]\n");
  if("$pieces1[0]" == "Response: Goodbye"){
    echo("11111111111");
  }
}
}
Asterisk Call Manager/1.1
Event: FullyBooted
Response: Success
Event: CoreShowChannel
Event: CoreShowChannel
Event: CoreShowChannelsComplete
Response: Goodbye
1
  • First explode the string to an array, then loop through it with a foreach, not the other way around. Commented May 26, 2013 at 13:00

2 Answers 2

1

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("\n", $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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

  if(trim($pieces1[0]) == "Response: Goodbye"){
    echo("11111111111");
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.