- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Escaping/encoding single quotes in JSON encoded HTML5 data attributes
To escape single quotes, use json_encode() to echo arrays in HTML5 data attributes.
printf('<article data-tags="%s">', htmlspecialchars(json_encode(array('html5', ...)), ENT_QUOTES, 'UTF-8'));
Or you can also using built-in
json_encode(array('html5', ...), JSON_HEX_APOS)
- Related Articles
- Escaping quotes while inserting records in MongoDB?
- URL Encoding in HTML5
- WebSockets Attributes in HTML5
- HTML5 Microdata Attributes
- Single quotes vs. double quotes in C or C++\n
- Single and Double Quotes in Perl
- How to use jQuery selectors on custom data attributes using HTML5?
- How to add single quotes to strings in an R data frame column?
- Store and retrieve arrays into and from HTML5 data attributes with jQuery?
- Creating custom attributes with HTML5
- How to escape single quotes in MySQL?
- Attributes and usage of element in HTML5
- Attributes and usage of element in HTML5
- Print newline in PHP in single quotes\n
- Using Data-Attributes (data-*) in CSS

Advertisements