How to show php content in textarea?

Discussion in 'PHP' started by kevinpham123, Nov 16, 2012.

  1. #1
    Hello. Does everyone know how to show php content in textarea?
     
    kevinpham123, Nov 16, 2012 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    something like this should work.

    
    $code = str_replace(array('<','>'),array('&gt;','&lt;'),$code);
    echo '<textarea>'.$code.'</textarea>';
    
    PHP:
     
    stephan2307, Nov 16, 2012 IP
  3. linkodev

    linkodev Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if you have the variable declared somewhere such as
    $money = 'This is my money
    PHP:
    echo it in your textarea like this

    <textarea><?php echo $money; ?> </textarea>
    PHP:
     
    linkodev, Nov 17, 2012 IP
  4. rohitink

    rohitink Active Member

    Messages:
    370
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Its a Common Mistake, which beginners may make. textarea has no attriibute like 'value'. So you need to show content in between the opening and closing brackets like ^^linkodev said.
     
    rohitink, Nov 17, 2012 IP
  5. linkodev

    linkodev Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks rohitink for pointing that out.
     
    linkodev, Nov 18, 2012 IP