IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Converting Textarea Return Characters To <br />


paulmason411
no avatar
Member [Level 1]
****
Group: Members
Posts: 69
Joined: 18-November 06
Member No.: 33,593



Post #1 post Dec 7 2007, 10:10 AM
Hi guys,

I have set up a form with a textarea. If I have text on multiple lines such as:

CODE
here is some content

here is some more content



then when I print it out as html it will be returned on one line like so:

CODE
here is some contenthere is some more content


When i look at the content in the database it looks just like the original way i entered it (contains the multiple lines).

Is there a function in php so that when i spit it out in html it retains the multiple line format?

Thanks in advance.
Go to the top of the page
+Quote Post
jlhaslip
no avatar
Insert Custom Title Here
*******************
Group: [MODERATOR]
Posts: 4,903
Joined: 24-July 05
From: Linux, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol
myCENT:81.50



Post #2 post Dec 7 2007, 12:54 PM
try this:
CODE
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);
Go to the top of the page
+Quote Post
mahirharoon
no avatar
Advanced Member
*******
Group: Members
Posts: 102
Joined: 25-November 07
Member No.: 53,695



Post #3 post Dec 7 2007, 02:02 PM
put \n at last of the line
Go to the top of the page
+Quote Post
paulmason411
no avatar
Member [Level 1]
****
Group: Members
Posts: 69
Joined: 18-November 06
Member No.: 33,593



Post #4 post Dec 7 2007, 02:07 PM
jlhaslip you've done it again. Thanks!
Go to the top of the page
+Quote Post
ewcreators
no avatar
Member [Level 1]
****
Group: Members
Posts: 59
Joined: 28-August 07
Member No.: 48,983



Post #5 post Dec 7 2007, 02:20 PM
QUOTE(paulmason411 @ Dec 7 2007, 10:07 AM) [snapback]361043[/snapback]
jlhaslip you've done it again. Thanks!

that may be sorta complex.
The easiest way is to use :
CODE
<?php
$line_break=nl2br($_POST['text']);
echo $line;
?>

nl2br() is a function which inserts a <br /> automatically at the end of every line.
Go to the top of the page
+Quote Post
jlhaslip
no avatar
Insert Custom Title Here
*******************
Group: [MODERATOR]
Posts: 4,903
Joined: 24-July 05
From: Linux, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol
myCENT:81.50



Post #6 post Dec 7 2007, 03:24 PM
CODE
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);

I use that in a function that replaces all the bad stuff in Emails, Comments, $_POST arrays, etc.
Yes, probably a little overkill checking for the hex values. And you are correct, the nl2br() would likely do it.

I had not had my morning coffee yet when I replied... tongue.gif
Go to the top of the page
+Quote Post
iGuest
no avatar
Hail Caesar!
*********************
Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



Post #7 post Jun 22 2008, 03:00 AM
character count
Converting Textarea Return Characters To


Guys teach me how to post the character count on php from the html textarea. I know how to do the wordcount but the character count is really my problem

Need help

-reply by abby
Go to the top of the page
+Quote Post
who?
no avatar
Newbie [Level 1]
*
Group: Members
Posts: 12
Joined: 10-April 06
Member No.: 21,606



Post #8 post Jul 9 2008, 11:23 PM
QUOTE(FeedBacker @ Jun 22 2008, 04:00 AM) [snapback]397022[/snapback]
character count

Converting Textarea Return Characters To
Guys teach me how to post the character count on php from the html textarea. I know how to do the wordcount but the character count is really my problem

Need help

-reply by abby


I'm not sure if I understand your problem, but try using strlen($str), where $str is the textarea value.

This post has been edited by who?: Jul 9 2008, 11:23 PM
Go to the top of the page
+Quote Post
optiplex
no avatar
Newbie [Level 3]
***
Group: [HOSTED]
Posts: 40
Joined: 26-June 08
From: Behind enemy
Member No.: 64,213



Post #9 post Jul 21 2008, 06:13 PM
Oh thats really simple!

you can replace newlines using str_replace

like this

CODE
$your_string = str_replace(array(chr(10), chr(13)), "<br />", $your_string);


or you can use nl2br

CODE
$your_string = nl2br($your_string);


BUT if you are showing html code anyway, you can write it in a textarea

like : <textarea><? echo $your_string; ?></textarea>

or using the <PRE> tag, like this:
<PRE><? echo $your_string; ?></PRE>

But there are more options afcourse
Thats it!

- optiplex

This post has been edited by optiplex: Jul 21 2008, 06:16 PM
Go to the top of the page
+Quote Post
gogoily
no avatar
Member [Level 3]
******
Group: Members
Posts: 99
Joined: 30-October 05
Member No.: 13,571



Post #10 post Aug 4 2008, 08:56 AM
There's a very useful function in PHP to handle this situation. The function is "nl2br()", try it and you'll find how cute PHP is wink.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   9 peroim 1,184 5th November 2006 - 11:23 PM
Last post by: bajanca
No New Posts   0 sonesay 1,594 11th July 2007 - 10:50 PM
Last post by: sonesay
No New Posts   0 Phoenix.Illusion 183 25th July 2009 - 06:59 AM
Last post by: Phoenix.Illusion
No New Posts   9 renegade-designs 5,468 2nd November 2009 - 03:42 AM
Last post by: iG-lada
No New Posts 8 karlo 3,530 6th February 2005 - 03:07 AM
Last post by: karlo
No New Posts   6 Agenator 1,373 16th June 2007 - 02:38 AM
Last post by: Agenator
No New Posts   7 Dodger 1,877 23rd February 2005 - 11:46 PM
Last post by: Caveman
No New Posts   0 Froglok 2,056 5th March 2005 - 08:49 PM
Last post by: Froglok
No New Posts   5 Paradox 3,143 9th March 2005 - 04:26 PM
Last post by: vizskywalker
No New Posts   2 kvarnerexpress 2,546 14th April 2005 - 09:05 AM
Last post by: cse-icons
No New Posts   3 -ladybug- 1,747 2nd March 2005 - 12:53 PM
Last post by: -moooo_im_a_fish-
No new   19 -hany- 3,968 19th January 2005 - 02:56 PM
Last post by: -aflm-
No New Posts 2 kylelnsn 1,072 1st June 2006 - 04:55 PM
Last post by: kylelnsn
No New Posts   1 -abajan- 4,304 4th March 2005 - 02:11 PM
Last post by: -coldkit-
No New Posts   1 Galahad 4,673 26th October 2007 - 07:50 PM
Last post by: Trap FeedBacker


 



RSS Open Discussion Time is now: 6th November 2009 - 07:58 PM

Web Hosting Powered by ComputingHost.com.