0

-------------php code ends here-------------

<script type="text/javascript">
    var e = <?php echo $tweetText; ?>; 
    var f = twemoji.parse(e);
    document.write(f);
</script>

-------------php code starts here-------------

If I put single quotes or double quotes before and after then it matches any ' or " inside the tweetText and doesn't let the string print to screen.

3

4 Answers 4

0

This solution works fine, just add ,,addslashes" to escape quotes

<script type="text/javascript">
    var e = '<?php echo addslashes($tweetText); ?>'; 
    var f = twemoji.parse(e);
    document.write(f);
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

And what if the string has a double-quote in it? It would come out as var e = 'He said, \"Yes, that\'s it.\"';
Have fun removing slashes in your code. This is not the correct solution to your problem.
0
<script type="text/javascript">
    var e = '<?php echo $tweetText; ?>'; 
    var f = twemoji.parse(e);
    document.write(f);
</script>

That's it

4 Comments

And if the Tweet looks like this: I love that you're a Leo.
can you explain your comment please @Halfstop?
I tried and this works fine, I don't understend what is the problem and why I get minus?
Does this look like valid JS? var e = 'I love that you're a Lew.';
0

The best way to do this would be with json_encode as @vivek said in a comment.

<script type="text/javascript">
var e = <?php echo json_encode($tweetText); ?>;
var f = twemoji.parse(e);
document.write(f);
</script>

Comments

-1

Try to put the whole string inside doublequotes, then escape the same - double quotes - inside the javascript string, with a simple str function:

<script type="text/javascript">
var e = "<?php echo str_replace('"','\"',$tweetText); ?>"; 
var f = twemoji.parse(e);
document.write(f);
</script>

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.