Bug #66069 [Opn->Nab]: UTF8 problem with substr
| From: | requinix@php.net | Date: | Sat, 09 Nov 2013 00:04:27 +0000 |
| Subject: | Bug #66069 [Opn->Nab]: UTF8 problem with substr | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182673@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66069&edit=1
ID: 66069
Updated by: requinix@php.net
Reported by: p dot danesh at afagh dot info
Summary: UTF8 problem with substr
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: LINUX
PHP Version: 5.5.5
Block user comment: N
Private report: N
New Comment:
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
substr() works with bytes, not logical characters. If you use it with a string in a multibyte
encoding then you might accidentally cut it off in the middle of a byte sequence. Which is what
happened for you.
Don't use substr() for a UTF-8 string.
Previous Comments:
------------------------------------------------------------------------
[2013-11-08 23:11:08] p dot danesh at afagh dot info
Description:
------------
---
From manual page: http://www.php.net/function.substr
---
Hello,
in UTF8 string , when we use substr , one character "�" seen at end of output.
we dont have problem in mb_substr.
Test script:
---------------
$str="ÙÙ
ÙÙÙ Ù
ØªÙ Ø³Ø§Ø¯Ù Ø¬ÙØª برش
ØªÙØ³Ø· تابع ساب اس ØªÛ Ø¢Ø± در Ù¾Û Ø§Ú
Ù¾Û";
echo substr($str ,0 ,28);
Expected result:
----------------
ÙÙ
ÙÙÙ Ù
ت٠ساد٠�
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66069&edit=1