javascript - How to echo php string safely in a java script onclick identifier -
please don't mark duplicate can't find working solution on similar questions. none of them seem fix specific string.
i have php variable...
<?php $og_description = 'lorem ipsum dolor sit amet, consectetur adipiscing elit. vivamus hendrerit cursus mi, nullam condi\'mentum posuere odio sed cursus.. proin posue\'re fermentum, ligula vel lacinia sollicitudin, libero quam ultrices quam, quis tristique orci... enim justo!' ?> the string above has same special characters using.
i trying echo onclick identifier. <?php echo $og_description; ?> not going work on own.
<a href="#" onclick="fb_publish('<?php echo $fb_app_url; ?>','<?php echo $og_title; ?>','images/icon.png','<?php echo $og_description; ?>'); return false;">post wall</a> i have tried these...
echo htmlspecialchars($og_description); echo json_encode($og_description); and few others nothing seemed fix string format not break identifier array.
does know how can fix this?
thanks josh
onclick="fb_publish(<?php echo htmlspecialchars(json_encode($string), ent_compat); ?>)" you need both escape/encode valid javascript syntax , then escape/encode valid html attribute.
Comments
Post a Comment