Results 1 to 2 of 2

Thread: htmlentities function not working

  1. #1
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default htmlentities function not working

    I am pulling information from a MySQL database and trying to change characters into html characters only it's not working, any ideas?

    Here's an example of the code:

    PHP Code:
    $query "SELECT * FROM mytable WHERE something='something'";
    $result mysql_query($query) or die(mysql_error()); 

    while (
    $info mysql_fetch_array($result))
        {
        print 
    htmlentities($info['somedata']) . "<br>";
        } 
    If one of the values returned is "something & something" it won't change it to "somthing &amp; something"
    -----------------
    I want to use the result of "$info['somedata']" in a url
    e.g.

    HTML Code:
    http://somthing.com?somthing=something%20&amp;%20something
    and not

    HTML Code:
    http://somthing.com?something=something & something
    only if I use $GET['something'];
    it only gets the value "something" not "something & something".

    Hope this makes sense!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's because you don't want it to become &amp;, you want it to become %26. See urlencode().
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •