php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80623 substring doesn't work with §,µ and £ even on online sandbox
Submitted: 2021-01-14 14:21 UTC Modified: 2021-01-14 14:35 UTC
From: albu dot consult at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 8.0.1 OS: window
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: albu dot consult at gmail dot com
New email:
PHP Version: OS:

 

 [2021-01-14 14:21 UTC] albu dot consult at gmail dot com
Description:
------------
$test = '§abcd';
$test1 = substr($test,1);
echo $test1;

It should return "abcd" it doesnt but: "�abcd"
I tested it does same thing with §, µ, £ and perhaps other char I didn't think of.

Test script:
---------------
$test = '§abcd';
$test1 = substr($test,1);
echo $test1;

Expected result:
----------------
abcd

Actual result:
--------------
�abcd

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-14 14:22 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2021-01-14 14:22 UTC] derick@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

These letters use more than one byte per character, and substr only operates on bytes. You want to use mb_substr instead.
 [2021-01-14 14:22 UTC] albu dot consult at gmail dot com
-Summary: substring doesn't work with §,µ and £ event on online sandbox +Summary: substring doesn't work with §,µ and £ even on online sandbox -Status: Not a bug +Status: Open
 [2021-01-14 14:22 UTC] albu dot consult at gmail dot com
typo
 [2021-01-14 14:35 UTC] sjon@php.net
-Status: Open +Status: Not a bug
 [2021-01-14 14:35 UTC] sjon@php.net
see comment from derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC