Welcome Guest, Not a member yet? Register   Sign In
Using JSON in data attributes with JS
#3

ivantcholakov, that Escaper class is very thorough. My only concern is that when testing, it took a 41 character string of json and turned it into 127 characters.

So this:


PHP Code:
$escaper = new Escaper('utf-8');
$str $escaper->escapeHtmlAttr(json_encode([
 
   'yodels' => 'Brian\'s',
 
   'lemons' => '"Lovely"'
]));
echo 
$str

Became this:


Code:
{"yodels":"Brian's","lemons":"\"Lovely\""}

If I've got a lot of json, I guess I might need to put it somewhere besides an attribute.

Thanks for the links. That Escaper class is pretty cool. Definitely useful and easier to use than rolling my own.
Reply


Messages In This Thread
RE: Using JSON in data attributes with JS - by skunkbad - 11-14-2017, 10:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB