Convert PHP_EOL to string value?, string should show '\r\n' in Windows |
Convert PHP_EOL to string value?, string should show '\r\n' in Windows |
CharlesEF |
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 |
Brian Chandler |
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 |
Brian Chandler |
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? |
CharlesEF |
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. |
CharlesEF |
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 |
|
Lo-Fi Version | Time is now: 19th April 2024 - 01:39 AM |