|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70479 Substr() appends invisible characters
Submitted: 2015-09-13 01:00 UTC Modified: 2015-09-13 01:29 UTC
From: nino dot skopac at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 7.0.0RC2 OS: Win 10 x64 (winver=10240)
Private report: No CVE-ID: None
 [2015-09-13 01:00 UTC] nino dot skopac at gmail dot com
When using substr() on v.7 RC2 on my local machine, I am getting different results than when I run the same script on my Linux webserver running v. 5.6.11

Test script:
$files = ob_get_clean();
$fs = explode("\n", $files);

foreach($fs as $f) {
	$ext = substr($f, strrpos($f, "."), strlen($f));
	$ext_trimmed = trim($ext);
	var_dump($ext, $ext_trimmed);

Expected result:
string(4) ".css"
string(4) ".css"
string(4) ".css"
string(4) ".css"
string(0) ""

Actual result:
string(5) ".css"
string(4) ".css"
string(5) ".css"
string(4) ".css"
string(0) ""
string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-13 01:19 UTC]
-Status: Open +Status: Feedback
 [2015-09-13 01:19 UTC]
Did you save that file using Windows-style line endings, which are \r\n and not \n?
 [2015-09-13 01:24 UTC] nino dot skopac at gmail dot com
I made the file out of scratch in Dreamweaver for Windows, so I guess so.
 [2015-09-13 01:29 UTC]
-Status: Feedback +Status: Not a bug
 [2015-09-13 01:29 UTC]
Then there you go.
 [2015-09-13 01:32 UTC] nino dot skopac at gmail dot com
Yep, I just tried PHP_EOL instead of "\n", and the result was as expected. Thanks for the feedback, friend.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 22:01:29 2024 UTC