1410
/* {{{ proto array get_html_translation_table([int table [, int quote_style]])
1411
/* {{{ proto array get_html_translation_table([int table [, int quote_style [, string charset_hint]]])
1411
1412
Returns the internal translation table used by htmlspecialchars and htmlentities */
1412
1413
PHP_FUNCTION(get_html_translation_table)
1414
1415
long which = HTML_SPECIALCHARS, quote_style = ENT_COMPAT;
1417
enum entity_charset charset = determine_charset(NULL TSRMLS_CC);
1418
unsigned char ind[5]; /* max # of 8-bit code units (4; for UTF-8) + 1 for \0 */
1420
char *charset_hint = NULL;
1421
int charset_hint_len;
1422
enum entity_charset charset;
1419
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &which, "e_style) == FAILURE) {
1424
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lls",
1425
&which, "e_style, &charset_hint, &charset_hint_len) == FAILURE) {
1429
charset = determine_charset(charset_hint TSRMLS_CC);
1423
1431
array_init(return_value);
1427
1433
switch (which) {
1429
for (j=0; entity_map[j].charset != cs_terminator; j++) {
1430
if (entity_map[j].charset != charset)
1435
for (j = 0; entity_map[j].charset != cs_terminator; j++) {
1436
if (entity_map[j].charset != charset)
1438
for (i = 0; i <= entity_map[j].endchar - entity_map[j].basechar; i++) {
1443
if (entity_map[j].table[i] == NULL)
1432
for (i = 0; i <= entity_map[j].endchar - entity_map[j].basechar; i++) {
1435
if (entity_map[j].table[i] == NULL)
1437
/* what about wide chars here ?? */
1438
ind[0] = i + entity_map[j].basechar;
1439
snprintf(buffer, sizeof(buffer), "&%s;", entity_map[j].table[i]);
1440
add_assoc_string(return_value, ind, buffer, 1);
1446
k = i + entity_map[j].basechar;
1450
written = php_utf32_utf8(ind, k);
1451
ind[written] = '\0';
1457
/* we have no mappings for these, but if we had... */
1459
default: /* one byte */
1461
ind[0] = (unsigned char)k;
1466
snprintf(buffer, sizeof(buffer), "&%s;", entity_map[j].table[i]);
1467
if (zend_hash_find(Z_ARRVAL_P(return_value), (const char*)ind, written+1, &dummy) == FAILURE) {
1468
/* in case of the single quote, which is repeated, the first one wins,
1469
* so don't replace the existint mapping */
1470
add_assoc_string(return_value, (const char*)ind, buffer, 1);
1446
case HTML_SPECIALCHARS:
1447
for (j = 0; basic_entities[j].charcode != 0; j++) {
1449
if (basic_entities[j].flags && (quote_style & basic_entities[j].flags) == 0)
1476
case HTML_SPECIALCHARS:
1477
add_assoc_stringl(return_value, "&", "&", sizeof("&") - 1, 1);
1478
for (j = 0; basic_entities[j].charcode != 0; j++) {
1479
if (basic_entities[j].flags && (quote_style & basic_entities[j].flags) == 0)
1452
ind[0] = (unsigned char)basic_entities[j].charcode;
1453
add_assoc_stringl(return_value, ind, basic_entities[j].entity, basic_entities[j].entitylen, 1);
1482
ind[0] = (unsigned char)basic_entities[j].charcode;
1484
if (zend_hash_find(Z_ARRVAL_P(return_value), (const char*)ind, 2, &dummy) == FAILURE) {
1485
add_assoc_stringl(return_value, ind, basic_entities[j].entity,
1486
basic_entities[j].entitylen, 1);
1455
add_assoc_stringl(return_value, "&", "&", sizeof("&") - 1, 1);