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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 30 = ?
Subscribe to this entry?

 
 [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: Thu Apr 25 15:01:30 2024 UTC