Re: Counterpart to htmlentities function: unhtmlentities

From: Date: Wed, 27 Feb 2002 03:27:25 +0000
Subject: Re: Counterpart to htmlentities function: unhtmlentities
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-80425@lists.php.net to get a copy of this message
Quick fix Brad Fisher wrote:
PHPAPI char* php_str_unhtmlentities(char *str, unsigned int *resultlen)
PHPAPI char* php_str_unhtmlentities(char *str, unsigned int *resultlen TSRMLS_DC) Use memcpy instead of strcpy/strncpy. strcpy() won't work when user uses UCS-4 or like.
/* BF 6/11/01 (brad@info-link.net) */ /* {{{ proto string unhtmlentities(string str) Translates HTML entities in the given string into the appropriate characters. This function is the reverse of the standard PHP function htmlentities, however it DOES NOT currently use the same translation table. HTML entities have the form "&data;" where data is either the name of an entity (ie. >, <, ") or a # symbol followed by a decimal value from 0 to 255 (ie. ", &#38)
  str       = the string to decode
*/
proto cannot be that long, right? Anyone?
PHP_FUNCTION(unhtmlentities) {
        zval    **_str;         // The string
char *str; uint strlen = 0;
        uint    resultlen;
        char    *result;
        int myargc = ZEND_NUM_ARGS();
        if (myargc != 1 ||
            zend_get_parameters_ex(myargc, &_str) == FAILURE)
        {
                ZEND_WRONG_PARAM_COUNT();
        } //if
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &strlen) == FAILURE) { return; }
        // Convert the parameters to the appropriate types
        convert_to_string_ex(_str);
        resultlen = Z_STRLEN_PP(_str);
        result = php_str_unhtmlentities(Z_STRVAL_PP(_str), &resultlen);
result = php_str_unhtmlentities(str, &strlen);
        // Return the result
        RETURN_STRINGL(result, resultlen, 0);
} // PHP_FUNCTION(unhtmlentities) /* }}} */
-- Yasuo Ohgaki

« previous php.dev (#80425) next »