php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16714 explode()-function is not working correctly with Carriage Returns
Submitted: 2002-04-20 14:34 UTC Modified: 2002-04-21 13:04 UTC
From: webmaster at irgendware dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.0 OS: Windows XP Pro
Private report: No CVE-ID: None
 [2002-04-20 14:34 UTC] webmaster at irgendware dot com
Hello,

I just installed PHP4.2.0 RC4 on my System using IIS 5.1 with all patches. I installed PHP as ISAPI module, I ran before PHP 4.1.2 as CGI where the following worked correctly:

A propgram running in background saves every 10 secons the actual traffic into a file "jetzt.log", each line is separeted with a carraige return and a line feed "\r\n" - like any other textfile under windows.
For example it looks as the following:
34.865
9.763
0 Tage 1 Stunden 9 Minuten 41 Sekunden
 16 

And here is my script:
<?
   $fp = fopen("jetzt.log","r");
   $file = fread($fp, filesize ("jetzt.log"));
   fclose($fp);
   $haufen = explode("\r\n", $file)
   echo "Downstream: ".$haufen[0]."<br />\r\n";
   echo "Upstream: ".$haufen[1]."<br />\r\n";
   echo "Uptime: ".$haufen[2]."<br />\r\n";
   echo "CPU Usage: ".$haufen[3]."%";
?>

In PHP 4.1.2 the content of jetzt.log was seperated into the array $haufen and the script printed it fine out. Since PHP 4.2.0 all content of jetzt.log is written into $haufen[0], including carriage returns and line feeds. It is the same when I only use "\r" as seperator; when I use "\n", the content is correctly seperated but at the end of each line there is stil a carriage return.

I found a comparable problem at http://bugs.php.net/bug.php?id=3428

Best regards
    Mark Aslan Kuschel

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-21 13:04 UTC] sander@php.net
You can just use \n for that. Or open the script as binary. (PHP translates \r\n on Windows to \n, unless you've opened the file as binary)
 [2003-02-24 14:54 UTC] Slava at Philips dot com
Related report #16714:

Problem is not 'Bogus', it's Real.
Different behavior in Linux and Windows with same set of tools.

Problem confirmed with Win (tested with IIS  XP Pro and 2K Server) and PHP 4.3.1: When string has 'return' in it, will not be exploded with 'return', however 'space' will explode where 'return' symbol is.

Same script working fine for PHP 4.2 & Linux, however for Windows in 'Explode' function all 'returns' must be replaced with 'space' for script to work.

I?m editing script in 'Notepad' and
'return' above mean "
", not "\r".

Reagrds

Slava
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 02:01:28 2024 UTC