Page 1 of 1

Text Area Line Break Problem

Posted: Tue Dec 02, 2003 7:54 pm
by locell
I'm gathering emails from a text area like so:

email1@server.com
email2@server.com
email3@server.com

When I try to print it out on the next page or split()
them nothing happends, and they come out like:
email1@server.com email2@server.com email3@server.com

What should I do?

Here is the code:

<?php
$leadmail_email_addresses2 = nl2br($leadmail_email_addresses);
$email_c = 0;


$emails_html = split("\r\n", $leadmail_email_addresses);
$email_c = count($emails_html);


?>
<?php echo($email_c); ?>
<?php echo($leadmail_email_addresses3); ?>

Posted: Tue Dec 02, 2003 8:38 pm
by microthick
Are you sure that "\r\n" is the correct delimiter?

To test, look at the nth and (n+1)th elements of the string and ord() them.

ord($string) will return the ascii value of the first character of $string. Compare that to an ascii table to see if it really is the carriage return.

Posted: Tue Dec 02, 2003 10:54 pm
by daveheinzel
I had this same problem tonight, and I somewhere I found this nifty little thing:

nl2br()

When info is entered into my database using PHP, I don't treat line breaks. But when that data is retreived, nl2br() adds an html <br /> before the line break, reformatting the text to as it was entered.

I used it like this:

after you get your query results, do something like this:

echo nl2br("$results['emailaddresses']");

It worked for me, and I don't know much about PHP, so I'm sorry I can't elaborate.

Posted: Wed Dec 03, 2003 3:18 am
by mchaggis
The problem is simple as is the solution:

Code: Select all

<?php
# Re-Format the new lines to standard unix format
$leadmail_email_addresses = ereg_replace("\r\n","\n",$leadmail_email_addresses);

# Create an Array of the emails
$emails_html = split("\n",$leadmail_email_addresses);

$email_c = count($emails_html); 

echo $email_c; 
echo nl2br($leadmail_email_addresses); 
# Or
echo join('<br />', emails_html);
?>
[edit of a typo --JAM ;)]

Posted: Wed Dec 03, 2003 10:52 am
by mrvanjohnson
I think mchaggis meant to say

Code: Select all

<?php
echo nl2br($leadmail_email_addresses);
?>
not

Code: Select all

<?php
echo nr2br($leadmail_email_addresses);
?>