Home > Archive > PHP Language > July 2004 > CRLF to <br>
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Steven Stern 2004-07-28, 3:56 pm |
| I've written a script that takes stuff from a database and creates HTML that
is then imported into Word. As a result, line ending characters are
important. I can't control the source, so some of the lines are terminated
with \n, some with \r, and some with \r\n. Users paste text from whatever
into a form that stores the text into the database.
What I want to do is to have each logical line end with "<br>\n". (The "\n" is
just to make the HTML easier to read when I'm debugging the raw output.)
I've got it working, but is there a more elegant way to do it than this, using
two str_replace calls?
$eols=array("\n","\r");
$line_from_db = str_replace("\r\n","\n",$line_from_db);
$line_from_db = str_replace($eols,"<br>",$line_from_db)."\n";
| |
| Andy Barfield 2004-07-28, 3:56 pm |
| Steven Stern wrote:
> I've got it working, but is there a more elegant way to do it than
this, using
> two str_replace calls?
http://www.php.net/nl2br
| |
|
|
"Steven Stern" <sdsternNOSPAMHERE@NOSPAMHEREmindspring.com> wrote in message
news:fggfg055bk977q7qm8ig3k5v6dh1bvag99@
4ax.com...
> I've written a script that takes stuff from a database and creates HTML
that
> is then imported into Word. As a result, line ending characters are
> important. I can't control the source, so some of the lines are
terminated
> with \n, some with \r, and some with \r\n. Users paste text from whatever
> into a form that stores the text into the database.
>
> What I want to do is to have each logical line end with "<br>\n". (The
"\n" is
> just to make the HTML easier to read when I'm debugging the raw output.)
>
> I've got it working, but is there a more elegant way to do it than this,
using
> two str_replace calls?
>
> $eols=array("\n","\r");
> $line_from_db = str_replace("\r\n","\n",$line_from_db);
> $line_from_db =
str_replace($eols,"<br>",$line_from_db)."\n";
See if setting the wrap attribute of the form textbox element to 'hard' or
'physical' makes a diffeence.
RU
| |
|
| "Steven Stern" wrote:
> I’ve written a script that takes stuff from a database and
> creates HTML that
> is then imported into Word. As a result, line ending characters
are
> important. I can’t control the source, so some of the lines are
> terminated
> with \n, some with \r, and some with \r\n. Users paste text
from
> whatever
> into a form that stores the text into the database.
>
> What I want to do is to have each logical line end with
> "<br>\n". (The "\n" is
> just to make the HTML easier to read when I’m debugging the raw
> output.)
>
> I’ve got it working, but is there a more elegant way to do it
> than this, using
> two str_replace calls?
>
> $eols=array("\n","\r");
> $line_from_db = str_replace("\r\n","\n",$line_from_db);
> $line_from_db =
> str_replace($eols,"<br>",$line_from_db)."\n";
$out = preg_replace( "/\r\n/", "\n", $input); //make breaks
single char
$out = preg_replace("/[\r\n]/", "<br>\n", $out);
You can use str_replace, more or less in a similar way.
--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-CRLF-br-ftopict134212.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=448678
|
|
|
|
|