Converting Textarea Return Characters To <br />

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Converting Textarea Return Characters To <br />

paulmason411
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.

Reply

jlhaslip
try this:
CODE
$value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value);

Reply

mahirharoon
put \n at last of the line

Reply

paulmason411
jlhaslip you've done it again. Thanks!

Reply

ewcreators
QUOTE(paulmason411 @ Dec 7 2007, 10:07 AM) *
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.

Reply

jlhaslip
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

Reply

iGuest
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

Reply

who?
QUOTE(FeedBacker @ Jun 22 2008, 04: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


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

Reply

optiplex
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

Reply

gogoily
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. display textarea with br in it - 1.99 hr back. (1)
  2. textarea php return problem - 2.82 hr back. (1)
  3. textarea return - 15.51 hr back. (1)
  4. php replace chr(10) textarea - 17.21 hr back. (1)
  5. converting return character - 21.17 hr back. (1)
  6. textarea
    problem in ie - 23.48 hr back. (1)
  7. return character in html - 36.91 hr back. (1)
  8. return character in php - 38.92 hr back. (1)
  9. textarea
    problem - 39.56 hr back. (1)
Similar Topics

Keywords : converting, textarea, return, characters,

  1. Validation Script - Detecting Illegal Characters
    preg_match to find illegal characters (0)
  2. Php Escaped Control Characters And Windows
    they aren't working for me. (3)
    In php coding, when you escape certain characters, they have an impact on the output of an
    echo'd or printed string. ie "\r\n\t" should give you a new line and a tab before
    outputting the content for a line of printing. They vary by OS, I know, but I have tried all the
    variations I can think of and can't seem to control output using them. Believe me, I have tried
    multiple variations and nothing works for me. I have checked the php.ini file for settings but I
    can't find where you can modify them. So the question is : Where do i look to conf....
  3. Converting Characters In A Variable To Individual Values In An Array
    turning variables into arrays (2)
    Say I have a variable such as $nav_item and it had to contents Home . IE: CODE
    $nav_item = 'Home'; How would I make so that $nav_item was an array and
    had the following contents? CODE $nav_item = array ('h', 'o',
    'm', 'e'); With the case changing (ie H would become h and U
    would become u ) EDIT: Okay found out that I could change the case with
    array_change_key_case ($nav_item, CASE_LOWER); ....
  4. Max Characters Is X?
    (3)
    I am currently making a code for my phpBB forum, where it will import the latest topics from a
    specific forum, and display it on the news section of my main page. But the width of that news
    section is very tiny, so I want the code to limit the numbers of characters to 25. So, let's
    say this is the full title: "This is the title which is a little too long so it needs to be
    shortened." This is what I want to show: "This is the title which ..." How can I do that?....
  5. Counting Characters Of Textarea...
    (3)
    good day webmasters... i am in need of a script that will count the inputted characters one will
    enter... i mean the script must count the number of characters in a textarea as i am entering
    characters to the textarea.. i know the logic but i cant translate it yet in PHP... so i hope you
    can help me... thanks a lot in advance... /blink.gif' border='0' style='vertical-align:middle'
    alt='blink.gif' /> ....
  6. Converting Dates
    converting epoch to MM-DD-YYY (1)
    So this is probably a basic and lame question, but how can I convert dates so I can then sort them?
    Right now, I have each part of a date as a separate variable: $month, $day, $year.
    I'd like to store them in the database as epoch. This way when I do a query I can sort them by
    date. I can figure out the datatype for the database later. I would also need to convert an epoch
    to Month-Day-Year later on when I want to display this. I'm sure this isn't too complicated
    but I figured asking for some suggestions anyway. Thanks!....

    1. Looking for converting, textarea, return, characters,

Searching Video's for converting, textarea, return, characters,
advertisement



Converting Textarea Return Characters To <br />



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE