note 109062 deleted from function.htmlspecialchars by cmb
| From: | cmb@php.net | Date: | Sun, 27 Oct 2019 09:21:01 +0000 |
| Subject: | note 109062 deleted from function.htmlspecialchars by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212860@lists.php.net to get a copy of this message | ||
Note Submitter: odegroot+php at gmail dot com
----
This function can be used to escape single quotes only, and not double quotes, by calling it as
follows.
<?php $escaped_string = htmlspecialchars($string, ENT_QUOTES & ~ENT_COMPAT, $encoding); ?>
This works because single/double quote escaping actually each have their own flag.
#define ENT_HTML_QUOTE_NONE 0
#define ENT_HTML_QUOTE_SINGLE 1
#define ENT_HTML_QUOTE_DOUBLE 2
#define ENT_COMPAT ENT_HTML_QUOTE_DOUBLE
#define ENT_QUOTES (ENT_HTML_QUOTE_DOUBLE | ENT_HTML_QUOTE_SINGLE)
#define ENT_NOQUOTES ENT_HTML_QUOTE_NONE
Snippet from: php-src/ext/standard/html.h
https://github.com/php/php-src/blob/master/ext/standard/html.h