diff options
author | Andrei Zmievski <andrei@php.net> | 2000-02-29 04:38:14 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2000-02-29 04:38:14 +0000 |
commit | 4c7af667a750eed929b507acb1dcc30ca441e401 (patch) | |
tree | f237017f168bee34f0a427dcc19dd0a2718f5502 | |
parent | b7c1735cb814badc965ff11e4819a4a03b559ad2 (diff) | |
download | php-git-4c7af667a750eed929b507acb1dcc30ca441e401.tar.gz |
Made php_escape_html_entities() as a separate function for export.
-rw-r--r-- | ext/standard/html.c | 37 | ||||
-rw-r--r-- | ext/standard/html.h | 2 |
2 files changed, 24 insertions, 15 deletions
diff --git a/ext/standard/html.c b/ext/standard/html.c index 83a0690432..41fef9c364 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -43,27 +43,18 @@ static char EntTable[][7] = "uuml","yacute","thorn","yuml" }; -static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) +PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all) { - pval **arg; - int i, len, maxlen; - unsigned char *old; + int i, maxlen, len; char *new; - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - maxlen = 2 * (*arg)->value.str.len; + maxlen = 2 * oldlen; if (maxlen < 128) maxlen = 128; new = emalloc (maxlen); len = 0; - old = (unsigned char *)(*arg)->value.str.val; - i = (*arg)->value.str.len; + i = oldlen; while (i--) { if (len + 9 > maxlen) new = erealloc (new, maxlen += 128); @@ -90,9 +81,25 @@ static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) old++; } new [len] = '\0'; + *newlen = len; + + return new; +} + +static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) +{ + zval **arg; + int len; + char *new; + + if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(arg); - RETVAL_STRINGL(new,len,1); - efree(new); + new = php_escape_html_entities((*arg)->value.str.val, (*arg)->value.str.len, &len, all); + RETVAL_STRINGL(new,len,0); } #define HTML_SPECIALCHARS 0 diff --git a/ext/standard/html.h b/ext/standard/html.h index 265f0656b7..082a0e9f08 100644 --- a/ext/standard/html.h +++ b/ext/standard/html.h @@ -38,4 +38,6 @@ PHP_FUNCTION(htmlspecialchars); PHP_FUNCTION(htmlentities); PHP_FUNCTION(get_html_translation_table); +PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all); + #endif /* _HTML_H */ |