April 13, 2011

php function returning a string with a new line?

Question by Jorge

In my first 3 days in coding my homework. I successfully did it. But when I got to school, my code have a problem. I have an ajax form and some php functions.

Here is an example.

$i = 1
if($i == 1) {
   echo "yes";
}
else {
   echo "no";
}

The answer in my sample is true. But in my case it’s always false. And I notice the ajax requests that the returned message was

    // new line
    // new line
yes
    // new line

That’s why it’s being false. What is the cause of this? I didn’t put any new line in my code.

Answer by Starx

If you want the easy way out of it, try this

ob_clean();
echo "yes";
exit;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!