diff options
author | Thies C. Arntzen <thies@php.net> | 1999-11-21 13:25:04 +0000 |
---|---|---|
committer | Thies C. Arntzen <thies@php.net> | 1999-11-21 13:25:04 +0000 |
commit | f24db304ee4c52c051abacfb695928aabce62bfb (patch) | |
tree | 754351833848b4805305c0bbb5742086a5e265f7 | |
parent | 2451ff5368c222c96e3616ca38708b07d6364bc2 (diff) | |
download | php-git-f24db304ee4c52c051abacfb695928aabce62bfb.tar.gz |
@- Implemented get_html_translation_table() function. (Thies)
(PHP get_html_translation_table) new function.
-rw-r--r-- | ext/standard/basic_functions.c | 2 | ||||
-rw-r--r-- | ext/standard/html.c | 53 | ||||
-rw-r--r-- | ext/standard/html.h | 3 |
3 files changed, 58 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 1166f224b1..ab473fcc53 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -105,6 +105,7 @@ function_entry basic_functions[] = { PHP_FE(htmlspecialchars, NULL) PHP_FE(htmlentities, NULL) + PHP_FE(get_html_translation_table, NULL) PHP_FE(md5, NULL) @@ -366,6 +367,7 @@ PHP_MINIT_FUNCTION(basic) REGISTER_INI_ENTRIES(); register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU); + register_html_constants(INIT_FUNC_ARGS_PASSTHRU); return SUCCESS; } diff --git a/ext/standard/html.c b/ext/standard/html.c index c04a257504..c1a5b9effb 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -95,6 +95,16 @@ static void _php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS, int all) efree(new); } +#define HTML_SPECIALCHARS 0 +#define HTML_ENTITIES 1 + +void register_html_constants(INIT_FUNC_ARGS) +{ + ELS_FETCH(); + REGISTER_LONG_CONSTANT("HTML_SPECIALCHARS", HTML_SPECIALCHARS, CONST_PERSISTENT|CONST_CS); + REGISTER_LONG_CONSTANT("HTML_ENTITIES", HTML_ENTITIES, CONST_PERSISTENT|CONST_CS); +} + /* {{{ proto string htmlspecialchars(string string) Convert special characters to HTML entities */ PHP_FUNCTION(htmlspecialchars) @@ -111,6 +121,49 @@ PHP_FUNCTION(htmlentities) } /* }}} */ +/* {{{ proto array get_html_translation_table([int whichone]) + returns the internal translation-table used by htmlspecialchars and htmlentities */ +PHP_FUNCTION(get_html_translation_table) +{ + zval **whichone; + int which = 0; + int ac = ARG_COUNT(ht); + int inx; + char ind[ 2 ]; + + if (ac < 0 || ac > 1 || getParametersEx(ac, &whichone) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (ac == 1) { + convert_to_long_ex(whichone); + which = (*whichone)->value.lval; + } + + array_init(return_value); + + ind[1] = 0; + + switch (which) { + case HTML_ENTITIES: + for (inx = 160; inx <= 255; inx++) { + char buffer[16]; + ind[0] = inx; + sprintf(buffer,"&%s;",EntTable[inx-160]); + add_assoc_string(return_value,ind,buffer,1); + } + /* break thru */ + + case HTML_SPECIALCHARS: + ind[0]=38; add_assoc_string(return_value,ind,"&",1); + ind[0]=34; add_assoc_string(return_value,ind,""",1); + ind[0]=60; add_assoc_string(return_value,ind,"<",1); + ind[0]=62; add_assoc_string(return_value,ind,">",1); + break; + } +} +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/ext/standard/html.h b/ext/standard/html.h index 3baddaf46e..265f0656b7 100644 --- a/ext/standard/html.h +++ b/ext/standard/html.h @@ -32,7 +32,10 @@ #ifndef _HTML_H #define _HTML_H +void register_html_constants(INIT_FUNC_ARGS); + PHP_FUNCTION(htmlspecialchars); PHP_FUNCTION(htmlentities); +PHP_FUNCTION(get_html_translation_table); #endif /* _HTML_H */ |