Bug #70479 [Com]: Substr() appends invisible characters

From: Date: Sun, 13 Sep 2015 01:32:30 +0000
Subject: Bug #70479 [Com]: Substr() appends invisible characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195977@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70479&edit=1 ID: 70479 Comment by: nino dot skopac at gmail dot com Reported by: nino dot skopac at gmail dot com Summary: Substr() appends invisible characters Status: Not a bug Type: Bug Package: Strings related Operating System: Win 10 x64 (winver=10240) PHP Version: 7.0.0RC2 Block user comment: N Private report: N New Comment: Yep, I just tried PHP_EOL instead of "\n", and the result was as expected. Thanks for the feedback, friend. Previous Comments: ------------------------------------------------------------------------ [2015-09-13 01:29:23] requinix@php.net Then there you go. ------------------------------------------------------------------------ [2015-09-13 01:24:25] 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:19:51] requinix@php.net Did you save that file using Windows-style line endings, which are \r\n and not \n? ------------------------------------------------------------------------ [2015-09-13 01:00:05] 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) "" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70479&edit=1

« previous php.bugs (#195977) next »