SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Para's Avatar
    Join Date
    Mar 2005
    Location
    London UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can i replace </textarea> with &lt;/textarea&gt;

    Hi i have a script that echos data within a <textarea>MY DATA</textarea>

    The probelm is that sometimes my data contains </textarea> tags, and it obviasly closes the main tag to early.

    I no that using &lt;/textarea&gt; instead solves the issue, but i need my script to to replace the unwanted </textarea> tags automaticly.

    Below i have included the script that displays the data

    PHP Code:
    <?php
    $sql 
    "SELECT * FROM data WHERE id=".$_GET['id'];
    $rs $db->Execute$sql );
    $codes $rs->fields['codes'];
    if (
    $codes2 == "") {
    echo 
    "";
    } else {
        echo 
    "<textarea cols=50 rows=15 onClick=\"highlight(this);\">$codes</textarea>";
    }
    ?>
    NOTE: $codes is the data output.

    Thanks in advance for any help

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $codes htmlspecialchars($codesENT_QUOTES); 
    You should get to know this function. It's necessary any time you ouput content that may contain " ' < > & etc. Especially if you're outputting to a HTML attribute where one of those characters will break the quotes in the HTML.

    & should be escaped regardless of where in the document it appears (even in link href attributes)

  3. #3
    SitePoint Zealot Para's Avatar
    Join Date
    Mar 2005
    Location
    London UK
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks cranial-bore, works perfect.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •