1

Ok so i have an input field that generates some text in html form (yea, don't ask). I set it as a php variable and then try to display it in a colorbox pop-up.

My text, as generated:

$text = '<h1>Some title</h1><p>Some text</p>';

And i try to use it like so:

$.colorbox({html:"'.$text.'"});

Obviously the js breaks as i would need to escape my string somehow. Tried htmlspecialchars() and alike but it does not help.

Thanks, and apologies for (i feel) incredibly noobie question.

1 Answer 1

2

JSON is JavaScript literals.

... $.colorbox({html:' . json_encode($text) . '}); ...
Sign up to request clarification or add additional context in comments.

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.