Astrid
Astrid

Reputation: 1312

php html multiple quotation marks invalid code

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

Answers (2)

user1646111
user1646111

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

Hanky Panky
Hanky Panky

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

Related Questions