Jump to content

use of CDATA within PHP


mklkm

Recommended Posts

I'm a front-end designer with a limited knowledge of PHP, though I'm learning through development on platforms like Drupal and Wordpress.

 

For a recent WP site, I installed a plug-in that does not validate due to parsing issues.  I added a CDATA tag and while it did validate, the plug-in stopped working.

 

Below is the pertinent part of the code--you can see where I added the tag in bold.  I really have no experience debugging PHP, so any guidance or suggestions whatsoever would be helpful!  Not sure if I'm missing an important escape or what...  Thanks!

 

echo "<script type=\"text/javascript\">\n";

echo "<![CDATA[\n";

echo "quoteRotator = {\n";

echo "\"i\":1,\n";

echo "\"quotes\" : [\n";

$i=0;

foreach($results as $result){

 

echo "\"$result->quote";

if($result->author != '')

 

echo "<span class=quoter'>-$result->author</span>";

echo "\",\n";

 

$i++;

}

 

echo ],\n";

echo "\"num_quotes\" : $i,\n";

echo "\t\"opac\":100,\n";

echo "\t\"showFading\":1,\n";

echo "\"quotesInit\":function(){\n";

echo "\tif(this.num_quotes>0){\n";

echo "\tdocument.getElementById('quoterotator').style.opacity=0.0\n";

echo "\tdocument.getElementById('quoterotator').style.filter=\"alpha(opacity=0.0)\"\n";

echo "\tnew Effect.Appear('quoterotator',{duration:".  $options['fade'] . "})\n";

echo "\t\tdocument.getElementById('quoterotator').innerHTML=this.quotes[0]\n";

echo "\t}\n";

echo "\telse{\n";

echo "\t\tdocument.getElementById('quoterotator').innerHTML=\"No Quotes Found!!!\"\n";

echo "\t}\n";

echo "\tif(this.num_quotes>1){\n";

echo "\t\tsetInterval(\"quoteRotator.quoteRotate()\", " . ($options['delay']*1000+$options['fade']*1000) . ")\n";

echo "\t}\n";

echo "},\n";

echo "\"quoteRotate\":function(){\n";

echo "\tdocument.getElementById('quoterotator').style.opacity=0.0\n";

echo "\tdocument.getElementById('quoterotator').style.filter=\"alpha(opacity=0.0)\"\n";

echo "\tnew Effect.Appear('quoterotator',{duration:" . $options['fade'] . "})\n";

echo "\tdocument.getElementById('quoterotator').innerHTML=this.quotes[this.i]\n";

echo "\tthis.i++\n";

echo "\tif(this.i==this.num_quotes){\n";

echo "\t\tthis.i=0\n";

echo "\t}\n";

echo "}\n";

echo "}\n";

            echo "]]>";

echo "</script>";

Link to comment
https://forums.phpfreaks.com/topic/167198-use-of-cdata-within-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.