Html special charachters

Discussion in 'PHP' started by minhazikram, Jan 6, 2012.

  1. #1
    <form >
    <td>
    <textarea name="specification" cols="30" rows="20" ></textarea>
    </td>
    <tr>
    <td><input type="submit" name="submit" value="ADD"></td>
    </tr>
    </form>


    this is my form field and it takes input succesfully. but when displaying the result, the result contains many html special charachters like \nl,<br /> tags Which i donot want to display in the result page.

    my output code is as follows

    <tr>
    <td><?php echo $specification; ?></td><td><?php echo (strtoupper(trim($model_by_id['specification']))) ;?></td>
    </tr>


    can anyone tell me that how to avoid displaying the html \nl,<br />,\r tags in the output.

    suppose if i give input like:

    INPUT:
    a quick brown fox
    jumps over the lazy dog.

    Output:
    a quick brown fox\nl
    jumps over the lazy dog.

    The thing is I donot want the \nl tag to showup. As it looks unusual
     
    minhazikram, Jan 6, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    nl2br is a function to rename the \n to br

    but you can also remove them by using str_replace("\n", "", $str) :)
     
    EricBruggema, Jan 7, 2012 IP
  3. t3od0r

    t3od0r Well-Known Member

    Messages:
    334
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    155
    #3
    t3od0r, Jan 7, 2012 IP
  4. minhazikram

    minhazikram Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    There is another problem. What ever i give input in the text area aforementioned the output always shows something like, if I give input like

    INPUT :
    specification : dsgnx
    price : sdubsd

    output gives result like this :
    specification : dsgnx\r\n price: sdubsd\r\n

    how can i remove these \r\n tags
     
    minhazikram, Jan 7, 2012 IP
  5. minhazikram

    minhazikram Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    There is another problem. What ever i give input in the text area aforementioned the output always shows something like, if I give input like

    INPUT :
    specification : dsgnx
    price : sdubsd

    output gives result like this :
    specification : dsgnx\r\n price: sdubsd\r\n

    how can i remove these \r\n tags
     
    minhazikram, Jan 7, 2012 IP
  6. JamesD31

    JamesD31 Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #6
    I wrote a "praragraphization" function that turns all \r\n's (and all their combos) into <p></p> - just change what you want the code to do below:

    
    /*** PARAGRAPHIZE ***/
    function paragraphize($string, $delimit = "\\r\\n") {
    	$paragraphs = explode($delimit, $string);
    	
    	for($i = 0; $i<sizeof($paragraphs); $i++) {
    		if($paragraphs[$i]) $paragraphs[$i] = '<p>'. $paragraphs[$i] .'</p>';
    		else $paragraphs[$i] = "";
    	}
    	
    	return implode('', $paragraphs);
    }
    
    Code (markup):
    Ultimately all you have to do is remove the <p></p> parts and you should have it how you want it.
     
    JamesD31, Jan 7, 2012 IP