Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-13-2004, 10:32 AM   #1 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
MAC new line?

i have a <textarea> input field i am using to collect userdata. when i am parsing through the data, most text (windows & linux) is just fine. however, when a MAC user submits something its just 1 big bunch of text. i am replacing "\n" with "<br>" when displaying the text.

do macs send newlines in a different format?

i havent looked anywhere else, just figured someone on here would konw.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 01-13-2004, 11:41 AM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
for newlines:
unix uses linefeed ('\n')
macs use carriage return ('\r')
windows uses carriage return + linefeed ('\r\n')

however, some browsers may do translations of text fields.
joe_bruin is offline   Reply With Quote
Old 01-13-2004, 02:48 PM   #3 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
Thanks! I will check out the \r route tonight.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 01-13-2004, 05:30 PM   #4 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
Is there a standard way for me to replace all new lines with a different character? I simply changed my \n to \r but want to make sure this works for EVERYONE not just Windows and Mac. I need to implement something that takes everything info account.
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 01-13-2004, 05:52 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
\n\r ?
__________________
Mike
sde is offline   Reply With Quote
Old 01-13-2004, 08:44 PM   #6 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
here is what I have now.

PHP Code:
//this really come out of the database
//but you get the idea
$foo "this is something
this is something else
cool
sweet
yess
noooo"
;

$foo explode("\r","$foo");

//do some stuff to that array here 
when i 'explode' the string, i want it to work out for all cases of a new line (\n,\r,\n\r)
__________________


Urban Clothing
Admin is offline   Reply With Quote
Old 01-13-2004, 09:22 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
will \n\r work for both pc/mac ? if so, i'd do something like this:
PHP Code:
<?
$string 
str_replace("\\n","{newline}",$string);
$string str_replace("\\r","{newline}",$string);
$string str_replace("{newline}","\\r\\n",$string);
?>
__________________
Mike
sde is offline   Reply With Quote
Old 01-13-2004, 09:34 PM   #8 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Quote:
Originally posted by sde
will \n\r work for both pc/mac ? if so, i'd do something like this:
PHP Code:
<?
$string 
str_replace("\n","{newline}",$string);
$string str_replace("\r","{newline}",$string);
$string str_replace("{newline}","\r\n",$string);
?>
close. change the order and it works fine.

PHP Code:
<?
$string 
str_replace("\r\n","{newline}",$string);
$string str_replace("\n","{newline}",$string);
$string str_replace("\r","{newline}",$string);
?>
joe_bruin is offline   Reply With Quote
Old 01-13-2004, 09:38 PM   #9 (permalink)
Admin
$_['Your_Mom'];
 
Admin's Avatar
 
Join Date: May 2002
Location: Santee
Posts: 627
Admin is on a distinguished road
thanks joe, that looks like it will work perfect!
__________________


Urban Clothing
Admin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
writting progress to cl on one line sde Linux / BSD / OS X 4 11-08-2004 02:15 PM
Silly Question: Adding a line break in a string JeC PHP 4 03-17-2003 11:06 AM
cgi script Henry PHP 25 12-30-2002 07:54 AM
so where exactly is the line drawn for ... sde PHP 2 06-05-2002 10:18 AM


All times are GMT -8. The time now is 08:32 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting