|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78934 What do mbstring functions return when they fail?
Submitted: 2019-12-09 00:03 UTC Modified: 2019-12-09 00:11 UTC
From: anthony_rutledge_101 at yahoo dot com Assigned:
Status: Open Package: mbstring related
PHP Version: Irrelevant OS:
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.
Block user comment
Status: Assign to:
Bug Type:
From: anthony_rutledge_101 at yahoo dot com
New email:
PHP Version: OS:


 [2019-12-09 00:03 UTC] anthony_rutledge_101 at yahoo dot com
From manual page:

Hi. Short and sweet. Would you please add what mb_substr() returns when it fails to the manual page? Thank you. I would have given you the answer, but my PHP 7.2.7 on Windows (legacy) does not have the multi-byte extension installed. I'm moving to PHP 7.4 anyway.

Test script:
The manual is the issue, not the function (as far as I know).
Still, to save you time. :-)


$name = "Anthony";

echo $name . "<br>";

$newName = mb_substr($name, 0, 7);

echo $newName . "<br>";

$badName = mb_substr($name, 0, 20);

echo $badName . "<br>";

$badName = mb_substr($name, 20, 20);

echo $badName . "<br>";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-09 00:11 UTC]
-Summary: What does mb_substr() return when it fails? +Summary: What do mbstring functions return when they fail? -Package: Documentation problem +Package: mbstring related
 [2019-12-09 00:11 UTC]
As with most other PHP functions, if there is some sort of problem then it returns false.

Looks like others don't have this documented either.
 [2019-12-13 19:12 UTC] drtechno at mail dot com
well, it would be the same as substr() because its the same thing just with multi-byte characters instead of the 7 bit ascii.

so the rules should be:
 Returns the extracted part of string; or FALSE on failure, or an empty string. 

False output example would be subtracting more than the length of the word, and it is being used in a comparative state (ex: if(mb_substr($name, 0, 7)=="y"){ }).
 [2019-12-13 19:36 UTC] drtechno at mail dot com
Also, I should add and to remind everyone who uses php character filters like substr(), mbsubstr(), htmlentities(), and htmlspecialchars() to always include the coding inline, as sometimes the internal timing will return Null, then either the filter will not work, or will return an error.

mb_substr($name 0, 7, $encoding="UTF-8");

htmlentities($name, $flags=ENT_QUOTES, $encoding="UTF-8");
htmlentities($name, ENT_QUOTES, "UTF-8");
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 03:01:24 2021 UTC