Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single quote in file name - javascript,php

How can I deal with a quote in data that has to be there?

This javascript statement works fine until city name is "ST JOHN'S". We are not able to change the change the city name in database -or- use a more reliable key.

$('#map_output').html('<p><img src="img/map/<?=$CITY_OUT?>_map.PNG" width="600"></p>')
like image 590
robert Avatar asked Sep 12 '26 14:09

robert


1 Answers

Use htmlspecialchars().

EDIT: you use it (sorta) like json_encode:

<?=htmlspecialchars($CITY_OUT, ENT_QUOTES)?>

But htmlspecialchars is more semantic - json_encode is about generating JSON (internal, data representation), not about presentation.

Nick Craver is right though - it'll also work.

Edit: need ENT_QUOTES for rendering " ' " correctly...

like image 99
rsenna Avatar answered Sep 15 '26 04:09

rsenna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!