ます’s Blog - どうでもいい記事100選

どうでもいい記事100選

htmlentities関数とhtmspecialchars関数の(デフォルトの)挙動

大垣さんのトコで(にわかに)盛り上がっている
PHP_SELF」は利用していないので別に構わないのですが、htmlentities関数とhtmspecialchars関数の(デフォルトの)挙動は確かに。。。
うっかりすると忘れてしまう時がありますね。
という訳でデフォルトの動作を「ENT_QUOTES」にするタコさんパッチ。

--- php-4.4.2,orig/ext/standard/html.c	2006-01-01 22:46:57.000000000 +0900
+++ php-4.4.2/ext/standard/html.c	2006-02-28 09:18:39.000000000 +0900
@@ -952,7 +952,7 @@
 	char *str, *hint_charset = NULL;
 	int str_len, hint_charset_len = 0;
 	int len;
-	long quote_style = ENT_COMPAT;
+	long quote_style = ENT_QUOTES;
 	char *replaced;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len,
@@ -994,7 +994,7 @@
 {
 	char *str, *hint_charset = NULL;
 	int str_len, hint_charset_len, len; 
-	long quote_style = ENT_COMPAT;
+	long quote_style = ENT_QUOTES;
 	char *replaced;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len,
@@ -1020,7 +1020,7 @@
    Returns the internal translation table used by htmlspecialchars and htmlentities */
 PHP_FUNCTION(get_html_translation_table)
 {
-	long which = HTML_SPECIALCHARS, quote_style = ENT_COMPAT;
+	long which = HTML_SPECIALCHARS, quote_style = ENT_QUOTES;
 	int i, j;
 	char ind[2];
 	enum entity_charset charset = determine_charset(NULL TSRMLS_CC);

PHP5.1.2もついでに。

--- php-5.1.2,orig/ext/standard/html.c	2006-01-01 21:50:14.000000000 +0900
+++ php-5.1.2/ext/standard/html.c	2006-02-28 09:25:31.000000000 +0900
@@ -1177,7 +1177,7 @@
 	char *str, *hint_charset = NULL;
 	int str_len, hint_charset_len = 0;
 	int len;
-	long quote_style = ENT_COMPAT;
+	long quote_style = ENT_QUOTES;
 	char *replaced;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, &quote_style, &hint_charset, &hint_charset_len) == FAILURE) {
@@ -1218,7 +1218,7 @@
 {
 	char *str, *new_str, *e, *p;
 	int len, j, i, new_len;
-	long quote_style = ENT_COMPAT;
+	long quote_style = ENT_QUOTES;
 	struct basic_entities_dec basic_entities_dec[8];
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, &quote_style) == FAILURE) {
@@ -1284,7 +1284,7 @@
 {
 	char *str, *hint_charset = NULL;
 	int str_len, hint_charset_len, len;
-	long quote_style = ENT_COMPAT;
+	long quote_style = ENT_QUOTES;
 	char *replaced;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len,
@@ -1310,7 +1310,7 @@
    Returns the internal translation table used by htmlspecialchars and htmlentities */
 PHP_FUNCTION(get_html_translation_table)
 {
-	long which = HTML_SPECIALCHARS, quote_style = ENT_COMPAT;
+	long which = HTML_SPECIALCHARS, quote_style = ENT_QUOTES;
 	int i, j;
 	char ind[2];
 	enum entity_charset charset = determine_charset(NULL TSRMLS_CC);