Jump to content

PHP Newline problem


MRGRIM
 Share

Recommended Posts

$output = "#EXTM3Un#EXTINF:".$filelength.",".urldecode($_GET['play'])."n".str_replace("/", "", urldecode($_GET['folder']))."".urldecode($_GET['play']);

$newfile='live.m3u';

$file = fopen ($save_path.$newfile, "w");

fwrite($file, $output);

fclose ($file);

I am trying to write the $output to a file named live.m3u, however when the code executes it all ends up on the same line with a [] instead of a carridge return, the text it outputs is fine and if I manually open the file and put the code on 3 lines the .m3u will open. I have tried a couple of things but I can't seem to get n to work, does anyone have any suggestions?

Not sure if this should have gone into coding?

Link to comment
Share on other sites

:-P Nice one fella, works a treat off to find out what /r does

Are you on Windows or Linux/mac?

I think n works as a replacement to <br> when doing echo statments for html, but rn is when streaming data to a file.

On a MAC rn works like n on windows and linux for html <BR> though.

Link to comment
Share on other sites

  • 4 years later...

windows uses

\r\n

and linux is

\n

but for simplicity's sake, just use the php constant

PHP_EOL

(since 4.3.10 and 5.0.2) cite

the server decides what the correct line ending is for

it's environment and uses it.

enjoy!

Edited by xero
Link to comment
Share on other sites

windows uses

\r\n

and linux is

\n

but for simplicity's sake, just use the php constant

PHP_EOL

(since 4.3.10 and 5.0.2) cite

the server decides what the correct line ending is for

it's environment and uses it.

enjoy!

Nice! Thanks for that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...