Reputation: 1312
how can i make sure these quotation marks become valid in PHP?
<?
echo "oaktree.addItem('test1<img src='img.png'>', branch1, '');";
echo "oaktree.addItem('test2<img src='img.png'>', branch1, '');";
?>
the problem is in the tag... thanks
Upvotes: 1
Views: 1026
Reputation:
Try this:
<?php
echo <<<EOT
oaktree.addItem('test1<img src="img.png">', branch1, '');
oaktree.addItem('test2<img src="img.png">', branch1, '');
EOT;
?>
Upvotes: 1
Reputation: 46900
Your original code is correct as far as PHP syntax is concerned, but it does not output correctly formatted JavaScript, as you are already aware. You can use double quotes inside double quotes in PHP as long as you escape them properly. You can do
<?
echo "oaktree.addItem('test1<img src=\"img.png\">', branch1, '');";
echo "oaktree.addItem('test2<img src=\"img.png\">', branch1, '');";
?>
Upvotes: 1