Detect line break in textfield

Discussion in 'Programming' started by senloong, May 3, 2007.

  1. #1
    Does anyone know how to detect line break in textfield (without html editor) and convert to paragraph? Thanks in advance!
     
    senloong, May 3, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <?
    function lb2pg( $data )
    {
    	$return = null;
    	$array = split("\n", $data );
    	foreach( $array as $paragraph )
    	{
    		$return .= "<p>$paragraph</p>\n";
    	}
    	return $return;
    }
    echo lb2pg("Hello my name is joe\nI am from the uk\nI live in a house, not a box\nI walk with legs and not wheels");
    
    PHP:
    something like that .....
     
    krakjoe, May 4, 2007 IP
  3. senloong

    senloong Peon

    Messages:
    102
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much ,krakjoe.
     
    senloong, May 7, 2007 IP
  4. technoguy

    technoguy Notable Member

    Messages:
    4,395
    Likes Received:
    308
    Best Answers:
    0
    Trophy Points:
    205
    #4
    if you are using php then use nl2br function to replace null with br tags.
     
    technoguy, May 8, 2007 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    technoguy: I think you mean replace new lines (not nulls) with br tags...
     
    TwistMyArm, May 8, 2007 IP