Bug #51385 [Bgs]: htmlentities next substr with UTF-8

[email protected] ("baudav at gmail dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at http://bugs.php.net/bug.php?id=51385&edit=1

 ID:               51385
 User updated by:  baudav at gmail dot com
 Reported by:      baudav at gmail dot com
 Summary:          htmlentities next substr with UTF-8
 Status:           Bogus
 Type:             Bug
 Package:          *Unicode Issues
-Operating System: Windows 2003
+Operating System: W2k3 IIS6
-PHP Version:      5.3.2
+PHP Version:      5.3.2 vc9-nts

 New Comment:

Windows 2003 with IIS6 fastcgi; PHP 5.3.1 or 5.3.2 vc9-nts


Previous Comments:
------------------------------------------------------------------------
[2010-03-25 05:24:44] [email protected]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Like most PHP functions, substr() is not multibyte-aware. You may prefer
to use 
mb_substr() instead.

------------------------------------------------------------------------
[2010-03-25 05:18:11] baudav at gmail dot com

Description:
------------
substr not truncate UTF-8 correctly, and generate bad UTF-8 string.

test script must be writen in UTF-8

Test script:
---------------
<?php
$str = 'câble TOSLink mâle/mâle (1.5 à 25m)';
$etc = '...';

echo htmlentities(substr($str, 0, 33). $etc, ENT_QUOTES, 'UTF-8')

?>

Expected result:
----------------
câble TOSLink mâle/mâle (1.5 ...

Actual result:
--------------
no return, just PHP error logged: 

PHP Warning:  htmlentities(): Invalid multibyte sequence in argument in
C:\DATA\WWW\test.php on line 5

change substr($str, 0, 33) by substr($str, 0, 32), it's work


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51385&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.