iliaa           Mon Mar  7 14:37:28 2005 EDT

  Modified files:              
    /php-src/ext/standard       basic_functions.c html.c html.h 
    /php-src    NEWS 
  Log:
  Added htmlspecialchars_decode() function for fast conversion from
  htmlspecialchars() generated entities back to characters.
  
  
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.704&r2=1.705&ty=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.704 
php-src/ext/standard/basic_functions.c:1.705
--- php-src/ext/standard/basic_functions.c:1.704        Tue Jan 18 05:38:03 2005
+++ php-src/ext/standard/basic_functions.c      Mon Mar  7 14:37:26 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.704 2005/01/18 10:38:03 dmitry Exp $ */
+/* $Id: basic_functions.c,v 1.705 2005/03/07 19:37:26 iliaa Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -192,6 +192,7 @@
        PHP_FE(htmlspecialchars,                                                
                                                NULL)
        PHP_FE(htmlentities,                                                    
                                                NULL)
        PHP_FE(html_entity_decode,                                              
                                                NULL)
+       PHP_FE(htmlspecialchars_decode,                                         
                                                NULL)
        PHP_FE(get_html_translation_table,                                      
                                        NULL)
        PHP_FE(sha1,                                                            
                                                        NULL)
        PHP_FE(sha1_file,                                                       
                                                        NULL)
http://cvs.php.net/diff.php/php-src/ext/standard/html.c?r1=1.102&r2=1.103&ty=u
Index: php-src/ext/standard/html.c
diff -u php-src/ext/standard/html.c:1.102 php-src/ext/standard/html.c:1.103
--- php-src/ext/standard/html.c:1.102   Sun Mar  6 14:36:51 2005
+++ php-src/ext/standard/html.c Mon Mar  7 14:37:26 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: html.c,v 1.102 2005/03/06 19:36:51 iliaa Exp $ */
+/* $Id: html.c,v 1.103 2005/03/07 19:37:26 iliaa Exp $ */
 
 /*
  * HTML entity resources:
@@ -1206,6 +1206,57 @@
 }
 /* }}} */
 
+/* {{{ proto string htmlspecialchars(string string [, int quote_style])
+   Convert special HTML entities back to characters */
+PHP_FUNCTION(htmlspecialchars_decode)
+{
+       char *str, *new_str, *e, *p;
+       int len, i, new_len;
+       long quote_style = ENT_COMPAT;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &len, 
&quote_style) == FAILURE) {
+               return;
+       }
+
+       new_str = estrndup(str, len);
+       new_len = len;
+
+       for (i = 0; basic_entities[i].charcode != 0; i++) {
+               if (basic_entities[i].flags && !(quote_style & 
basic_entities[i].flags)) {
+                       continue;
+               }
+
+               e = new_str + new_len;
+               p = new_str;
+
+               while ((p = php_memnstr(p, basic_entities[i].entity, 
basic_entities[i].entitylen, e))) {
+                       int e_len = basic_entities[i].entitylen - 1;
+               
+                       *p++ = basic_entities[i].charcode;
+                       memmove(p, p + e_len, (e - p - e_len));
+
+                       new_len -= e_len;       
+                       e -= e_len;
+               }
+       }
+
+       e = new_str + new_len;
+       p = new_str;
+       while ((p = php_memnstr(p, "&", sizeof("&") - 1, e))) {
+               int e_len = sizeof("&") - 2;
+
+               p++;
+               memmove(p, p + e_len, (e - p - e_len));
+
+               new_len -= e_len;       
+               e -= e_len;
+       }
+
+       new_str[new_len] = '\0';
+       RETURN_STRINGL(new_str, new_len, 0);
+}
+/* }}} */
+
 /* {{{ proto string html_entity_decode(string string [, int quote_style][, 
string charset])
    Convert all HTML entities to their applicable characters */
 PHP_FUNCTION(html_entity_decode)
http://cvs.php.net/diff.php/php-src/ext/standard/html.h?r1=1.18&r2=1.19&ty=u
Index: php-src/ext/standard/html.h
diff -u php-src/ext/standard/html.h:1.18 php-src/ext/standard/html.h:1.19
--- php-src/ext/standard/html.h:1.18    Thu Jan  8 12:32:51 2004
+++ php-src/ext/standard/html.h Mon Mar  7 14:37:26 2005
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: html.h,v 1.18 2004/01/08 17:32:51 sniper Exp $ */
+/* $Id: html.h,v 1.19 2005/03/07 19:37:26 iliaa Exp $ */
 
 #ifndef HTML_H
 #define HTML_H
@@ -33,6 +33,7 @@
 
 PHP_FUNCTION(htmlspecialchars);
 PHP_FUNCTION(htmlentities);
+PHP_FUNCTION(htmlspecialchars_decode);
 PHP_FUNCTION(html_entity_decode);
 PHP_FUNCTION(get_html_translation_table);
 
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1847&r2=1.1848&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1847 php-src/NEWS:1.1848
--- php-src/NEWS:1.1847 Sun Mar  6 14:24:20 2005
+++ php-src/NEWS        Mon Mar  7 14:37:27 2005
@@ -53,6 +53,7 @@
   . inet_ntop() (Sara)
   . fputcsv() (David Sklar)
   . posix_access() (Magnus)
+  . htmlspecialchars_decode() (Ilia)
 - Added DomDocument::$recover property for parsing not well-formed
   XML Documents. (Christian)   
 - Added Cursor support for MySQL 5.0.x in mysqli (Georg)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to