[PHP] Hidden new line markers?
I am using a SELECT statement to grab all items from a database table and while looping through the results I am connecting the fields with tabs and adding a new line at the end of the row to create a tab delimited file. On one field I do a nl2br in order to preserve the spacing in the field. However, when I import it into Excel, it keeps treating the br / as a nl. Am I missing something? I tried removing \r and \n with str_replace and I have used trim but it still doesn't work how I'm expecting it to. Does anyone have any ideas on this? Jeff
Re: [PHP] Hidden new line markers?
nl2br() doesn't remove the newlines, it simply adds in the br / in before them. The str_replace should work, how are you trying to use it? ---John Holmes... - Original Message - From: Jeff Lewis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, March 24, 2003 2:56 PM Subject: [PHP] Hidden new line markers? I am using a SELECT statement to grab all items from a database table and while looping through the results I am connecting the fields with tabs and adding a new line at the end of the row to create a tab delimited file. On one field I do a nl2br in order to preserve the spacing in the field. However, when I import it into Excel, it keeps treating the br / as a nl. Am I missing something? I tried removing \r and \n with str_replace and I have used trim but it still doesn't work how I'm expecting it to. Does anyone have any ideas on this? Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hidden new line markers?
The data is being entered into a textarea and is being stored as it is entered but with an addslashes right before insertion. On the extract I am doing the following: $row[description] = stripslashes($row[description]); $row[description] = nl2br($row[description]); $row[description] = trim($row[description]); I was trying str_replace as follows but that wasn't working: $row[description] = str_replace(\n, , $row[description]); Also, I had them in one larger statement as opposed to three lines but when it wasn't working I broke it up to three individual lines to see if I could narrow it down to what was causing the issue. Jeff - Original Message - From: CPT John W. Holmes [EMAIL PROTECTED] To: Jeff Lewis [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, March 24, 2003 3:03 PM Subject: Re: [PHP] Hidden new line markers? nl2br() doesn't remove the newlines, it simply adds in the br / in before them. The str_replace should work, how are you trying to use it? ---John Holmes... - Original Message - From: Jeff Lewis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, March 24, 2003 2:56 PM Subject: [PHP] Hidden new line markers? I am using a SELECT statement to grab all items from a database table and while looping through the results I am connecting the fields with tabs and adding a new line at the end of the row to create a tab delimited file. On one field I do a nl2br in order to preserve the spacing in the field. However, when I import it into Excel, it keeps treating the br / as a nl. Am I missing something? I tried removing \r and \n with str_replace and I have used trim but it still doesn't work how I'm expecting it to. Does anyone have any ideas on this? Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hidden new line markers?
The data is being entered into a textarea and is being stored as it is entered but with an addslashes right before insertion. On the extract I am doing the following: $row[description] = stripslashes($row[description]); You don't have to use stripslashes() on data coming out of a database unless you have magic_quotes_runtime enabled. If you find that you do need to call it, then you're running addslashes() twice before the data is inserted. $row[description] = nl2br($row[description]); $row[description] = trim($row[description]); I was trying str_replace as follows but that wasn't working: $row[description] = str_replace(\n, , $row[description]); This will get rid of the \n, but leave the \r there. On windows, you'll still see a newline even with just the \r remaining. If you know everything is coming from Windows, replace \r\n with an empty string. Unix uses just a plain \n and Macs use just \r, while Windows uses \r\n. Adjust your str_replace accordingly if you need to account for data from all three possible OS. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hidden new line markers?
Ah! That did it, it's all on Windows and when I tried removing things I tried at one point removing the \r as i thought the nl2br changed the \n to br / Thanks a lot John :) Jeff - Original Message - From: CPT John W. Holmes [EMAIL PROTECTED] To: Jeff Lewis [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, March 24, 2003 3:36 PM Subject: Re: [PHP] Hidden new line markers? The data is being entered into a textarea and is being stored as it is entered but with an addslashes right before insertion. On the extract I am doing the following: $row[description] = stripslashes($row[description]); You don't have to use stripslashes() on data coming out of a database unless you have magic_quotes_runtime enabled. If you find that you do need to call it, then you're running addslashes() twice before the data is inserted. $row[description] = nl2br($row[description]); $row[description] = trim($row[description]); I was trying str_replace as follows but that wasn't working: $row[description] = str_replace(\n, , $row[description]); This will get rid of the \n, but leave the \r there. On windows, you'll still see a newline even with just the \r remaining. If you know everything is coming from Windows, replace \r\n with an empty string. Unix uses just a plain \n and Macs use just \r, while Windows uses \r\n. Adjust your str_replace accordingly if you need to account for data from all three possible OS. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php