Req #73088 [Opn->Wfx]: str_check_encoding and str_scrub

From: Date: Sun, 08 Jan 2017 17:23:41 +0000
Subject: Req #73088 [Opn->Wfx]: str_check_encoding and str_scrub
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206398@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73088&edit=1 ID: 73088 Updated by: krakjoe@php.net Reported by: masakielastic at gmail dot com Summary: str_check_encoding and str_scrub -Status: Open +Status: Wont fix Type: Feature/Change Request Package: mbstring related PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: See github thread: https://github.com/php/php-src/pull/2129#issuecomment-270061348 Previous Comments: ------------------------------------------------------------------------ [2016-09-19 21:25:17] masakielastic at gmail dot com @nikic The one of target is Symfony's polyfill-mbstring and Drupal adopt them. https://github.com/symfony/polyfill https://api.drupal.org/api/drupal/vendor!symfony!polyfill-mbstring!Mbstring.php/class/Mbstring/8.2.x Algthouh mb_strlen and mb_substr can properly handle ill-formed byte sequences, PCRE's functions iconv_strlen/iconv_substr can't handle them. These functions are used for emulating mbstring's functions. grapheme_strlen and grapheme_substr also cant't handle them. $str = "ab\x80cde"; var_dump( 6 === mb_strlen($str, 'UTF-8'), false === preg_match_all('/./su', $str), false === iconv_strlen($str, 'UTF-8'), NULL === grapheme_strlen($str) ); iconv cant't handle ill-formed byte properly even in 2016. https://sourceware.org/bugzilla/show_bug.cgi?id=2373 I will open other requests for adding encoding option to substr (chr and ord's pull requests exist) and new functions (str_at and str_codepoint_at and str_each_char and str_each_codepoint) and rethink the value of this feature request. ------------------------------------------------------------------------ [2016-09-15 10:43:21] nikic@php.net As these functions deal with multibyte strings, they naturally belong into the mbstring extension, which, as you mention, already has analogous functions. Why would these need to be mirrored into ext/standard? ------------------------------------------------------------------------ [2016-09-15 10:33:46] masakielastic at gmail dot com fixed title. ------------------------------------------------------------------------ [2016-09-15 10:26:36] masakielastic at gmail dot com Description: ------------ htmlspecialchars have an ability to check character encoding and replace ill-formed byte sequences (ENT_SUBSTITUTE) since PHP 5.4. The ability is useful for not only escaping special chars but general. Mbstring have same feture such as mb_check_encoding and mb_scrub (PHP 7.2 dev). bool str_check_encoding ([ string $str[,string $encoding = ini_get("default_charset") ]] ) bool str_scrub ([ string $str[,string $encoding = ini_get("default_charset") ]] ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73088&edit=1

« previous php.bugs (#206398) next »