I have a website with some Javascript rotating content with a fade. The script works fine until I add a PHP while loop inside it, then it fails. I'm using the PHP to pull content from wordpress posts.
here is the isolated code (http://jsfiddle.net/dzz8M/2/). You'll notice the script works as desired if you remove the PHP and you can see here (http://www.smartcallclaims.com/indexx.php/) that the php is outputting fine.
When you check the source of that link and look for the JavaScript from the JSfiddle you'll see the PHP has generated it's content inside the script. (I know it adds a <p>
tag, this is not the issue)
Can some please tell me why the PHP breaks the javascript?
Your problem is the one unescaped linebreak in the quotes:
This is not valid JavaScript. You have to escape it somehow, for example like by using
str_replace()
in the PHP functions, that create those strings.