php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69179 The problem is in string length with RTL languages
Submitted: 2015-03-04 07:53 UTC Modified: 2015-03-04 08:39 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rm dot nasir at hotmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.5Git-2015-03-04 (snap) OS: Windows 8.1 Enterprise 32bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rm dot nasir at hotmail dot com
New email:
PHP Version: OS:

 

 [2015-03-04 07:53 UTC] rm dot nasir at hotmail dot com
Description:
------------
Hi!

I got a problem with my PHP 5.5.12 which I got with WAMP Server.

PROBLEM:
  When I want to return the length of an Arabic string value it is not showing the exact length of the characters I wrote in that string PHP is increasing the length.

Test script:
---------------
header('Content-Type: text/html; charset=utf-8;');

// demo string by Pashto language
$myText = "دا يوه جمله ده";

// length of the string above is 14 characters
// you can test it with JavaScript in your browser console
// and that is returning the exact length 14 but in PHP
// it is showing 25

echo strlen( $myText ); // 25

// I also tested it with

var_dump( $myText ); // string 'دا يوه جمله ده' (length=25)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-04 08:39 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2015-03-04 08:39 UTC] ab@php.net
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

Thanks for reporting. strlen() is not multibyte aware, it delivers the count of bytes, not characters. What you do need is probably mb_strlen(), iconv_strlen() or alike with regard to the correct charset settings.

Cheers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC