textarea post fetch problem

Discussion in 'PHP' started by dizyn, Dec 18, 2009.

  1. #1
    Problem in fetching data from text area....
    When i enter some text in textarea like:

    Hi
    this is text message
    thanks

    but i try to fetch it using post method i get this text in one line.. how can i fix it it?

    ere is my code
    thank you

    
    if(isset($_POST["submit"]))
    {		
    	echo $_POST["shortDesc"];
    	exit;
    }
    
    PHP:
    
    <textarea name="shortDesc" cols="60" rows="4" id="shortDesc"></textarea>
    <br/>
    <input name="submit" type="submit" id="submit" value="  Submit  " />
    
    Code (markup):
     
    dizyn, Dec 18, 2009 IP
  2. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    change this echo $_POST["shortDesc"]; to
    echo nl2br($_POST["shortDesc"]);
    it will convert linebreaks to <br>
     
    xenon2010, Dec 18, 2009 IP
  3. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think the best thinge for that is
        echo  preg_replace( "#\n#si", '<br>',$_POST["shortDesc"]);
    PHP:
     
    astkboy2008, Dec 18, 2009 IP
  4. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    why do you need to use preg_replace if PHP have an easy built-in function can do this with 5 characters :D
     
    xenon2010, Dec 18, 2009 IP