Browse Source

@- Implemented get_html_translation_table() function. (Thies)

(PHP get_html_translation_table) new function.
experimetnal/RETURN_REF_PATCH
Thies C. Arntzen 27 years ago
parent
commit
f24db304ee
  1. 2
      ext/standard/basic_functions.c
  2. 53
      ext/standard/html.c
  3. 3
      ext/standard/html.h

2
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;
}

53
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,"&amp;",1);
ind[0]=34; add_assoc_string(return_value,ind,"&quot;",1);
ind[0]=60; add_assoc_string(return_value,ind,"&lt;",1);
ind[0]=62; add_assoc_string(return_value,ind,"&gt;",1);
break;
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4

3
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 */
Loading…
Cancel
Save