php.net |  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
Description:
------------
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:
---------------
<?php
error_reporting(E_ALL);
ob_start();
?>
resources/layout.css
resources/jquery.fancybox.css
<?php
$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"
bool(false)
string(0) ""


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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-13 01:19 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2015-09-13 01:19 UTC] requinix@php.net
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] requinix@php.net
-Status: Feedback +Status: Not a bug
 [2015-09-13 01:29 UTC] requinix@php.net
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: Tue Apr 16 06:01:30 2024 UTC