]> granicus.if.org Git - php/commitdiff
@- Implemented get_html_translation_table() function. (Thies)
authorThies C. Arntzen <thies@php.net>
Sun, 21 Nov 1999 13:25:04 +0000 (13:25 +0000)
committerThies C. Arntzen <thies@php.net>
Sun, 21 Nov 1999 13:25:04 +0000 (13:25 +0000)
(PHP get_html_translation_table) new function.

ext/standard/basic_functions.c
ext/standard/html.c
ext/standard/html.h

index 1166f224b1895b6839b6d6a6b1b4172f8200365f..ab473fcc53acacaece68d97d4a825c019b6353a7 100644 (file)
@@ -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;
 }
 
index c04a2575041e50bf2ebad5f97871f899c19c6533..c1a5b9effbb7011aaa387e5afd75bd243efa7161 100644 (file)
@@ -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
index 3baddaf46e7308680c8c32708c31c87df661ca7e..265f0656b7894786f6ff7f49cf68f0a423e73ce8 100644 (file)
 #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 */