1

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

2
  • What error are you getting? That looks fine Commented Apr 14, 2013 at 10:16
  • when i remove the <img> tag, it displays the context, otherwise it just stays empty (the page) Commented Apr 14, 2013 at 10:17

2 Answers 2

1

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, '');";
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Funny that this should be a downvote, I think you did not read the question well enough to justify that
1

Try this:

<?php
echo <<<EOT
    oaktree.addItem('test1<img src="img.png">', branch1, '');
    oaktree.addItem('test2<img src="img.png">', branch1, '');
EOT;
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.