The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Convert PHP_EOL to string value?, string should show '\r\n' in Windows
CharlesEF
post Oct 30 2014, 06:36 PM
Post #1


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Hi All,

Boy, I thought this would be easy but after searching and reading for several hours (maybe I'm using the wrong keywords) I'm asking for help. I want the actual characters of the PHP constant PHP_EOL to show in a string.

I want a platform independent way, which is why I'm using the constant PHP_EOL, to show the actual character sequence.


Thanks for any help,

Charles
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 31 2014, 12:26 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



I don't have the Answer, sorry, but I think you will not find a simple way of doing this -- i.e. there won't be a function string_escape() which converts newlines and tabs to their backslash representations. I would attack the problem by trying to remember how to address individual bytes within a string, then print them out one by one, with a switch for CR and LF.

I vaguely remember that you can just treat strings as arrays $string[0], or something involving the typically messy PHP syntax like curly brackets.

HTH
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 31 2014, 01:37 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



I tried this fragment:

CODE

$stest = "one\ntwo";
$s = str_split($stest);
echo '<p><tt>'; print_r($s); echo '</tt>';


But it seems that the newline "character" is represented by one byte on both Linux and Windows. Can you give an example of how to get definitely distinct byte strings?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Oct 31 2014, 09:52 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Thanks for your input. I too was only able to get 1 byte (13) returned during all my tests. After getting some sleep I think I'm approaching my problem from the wrong angle.

Converting PHP_EOL will not help me with my problem. What I'm trying to do is import data into my database using the MySQL command 'LOAD DATA LOCAL INFILE' (using a PHP script). The 'LINES TERMINATED BY' require the '\r\n' or '\n' character sequence. Since I develop on Windows and transfer to my web host running Linux, these 2 systems use different end of line characters, I will have to approach my problem by opening each file before import and find the EOL character before I actually start the import.

I mean, my data files were created on Windows so when I transfer them to my hosting site they will still have the Windows EOL characters, not Linux.
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jan 10 2015, 04:46 AM
Post #5


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(masonh928 @ Jan 4 2015, 05:41 PM) *

oh… Sorry I can't help.

:'(

I looked around the site and on google. Can't find anything there either. Are you still experiencing this issue?

No, I don't have a problem any more. I wrote a file i/o class to read the file and determine the EOL character(s).
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 01:39 AM