php - Alternative for htmlentities($string,ENT_SUBSTITUTE) -


i got bit of stupid question;

currently making website company on server has bit outdated php version (5.2.17). have database in many fields varchar characters 'é ä è ê' , on, have display in html page.

so version of php outdated (and not allowed updated because there parts of site must keep working , whom have no acces edit them) can't use htmlentities function ent_substitute argument, because added after version 5.4.

so question is:

does there exist alternative htmlentities($string,ent_substitute); or have write function myself kinds of strange characters, incomplete anyway.

define function handling ill-formed byte sequences , call function before passing string htmlentties. there various way define function.

at first, try uconverter::transcode if don't use windows.

http://pecl.php.net/package/intl

if willing handle bytes directly, see previous answer.

https://stackoverflow.com/a/13695364/531320

the last option develop php extension. php_next_utf8_char, it's not hard. here code sample. name "scrub" comes ruby 2.1 (see equivalent of iconv.conv("utf-8//ignore",...) in ruby 1.9.x?)

// header file // php_function(utf8_scrub);  #include "ext/standard/html.h" #include "ext/standard/php_smart_str.h"  const zend_function_entry utf8_string_functions[] = {     php_fe(utf8_scrub, null)     php_fe_end };  php_function(utf8_scrub) {     char *str = null;     int len, status;     size_t pos = 0, old_pos;     unsigned int code_point;     smart_str buf = {0};      if (zend_parse_parameters(zend_num_args() tsrmls_cc, "s", &str, &len) == failure) {         return;     }      while (pos < len) {          old_pos = pos;         code_point = php_next_utf8_char((const unsigned char *) str, len, &pos, &status);          if (status == failure) {              smart_str_appendl(&buf, "\xef\xbf\xbd", 3);          } else {              smart_str_appendl(&buf, str + old_pos, pos - old_pos);          }      }      smart_str_0(&buf);     return_stringl(buf.c, buf.len, 0);     smart_str_free(&buf); } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -