Results 1 to 2 of 2

Thread: html php quote escape

  1. #1
    Join Date
    May 2006
    Beans
    135

    html php quote escape

    here is the problem:
    $name = 'O\'brian';
    PHP Code:
    echo "<td>Leader:</td> <td><input type=text value='$name' name=leader></td><tr>"
    Any ideas? Thanks.

    So far I have tried:
    \ escape symbol before the '
    mysql_escape_string()
    addslashes()

    No success, the output is always Leader: O
    everything after the ' will not print.

    I was going to post this, but then a friend help me solved the problem so incase anyone is interested here is the modified code that works:

    PHP Code:
    echo '<td>Leader:</td> <td><input type=text value="'; echo$name; echo'" name=leader></td><tr>'

  2. #2
    Join Date
    May 2005
    Location
    Dallas, TX
    Beans
    116
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: html php quote escape

    It would probably be simpler to just concatentate the variables together:

    PHP Code:
    echo '<td>Leader:</td> <td><input type=text value="'.$name.'" name=leader></td><tr>'
    Code comes out much cleaner (and less to type, too). Of course, you'll need to ensure $name doesn't contain quote marks, as that will throw off your HTML. You might want to try htmlentities() or htmlspecialchars() to handle that.
    Last edited by Modred; June 22nd, 2007 at 07:19 AM.

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
  •