Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help htmlentities not working

    Hi all,

    I have been trying to use the htmlentities() function to convert some text but its not working for me

    here are some of my trials

    PHP Code:
    $orig "!@#$%^&*()<>,";

    echo 
    htmlentities($orig);

    echo 
    htmlspecialchars($orig);

    // It returns the same strings !@#$%^&*()<>", without converting the string 
    Please could it be some configuration problem?

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    If you're echoing that output in a html page, everything will appear the same. Viewing the source is the only way to check the changes. If you're running that script from the commandline, it should encode the <>& characters on output at least.

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much senoir coder for you fast and quick reply
    I am very grateful,
    it has solved m problem

    The problem i am encountering really is that i am trying to insert some records into a database and the contents contains some apostrophes when i insert it into the database, it shows some unknown characters for me

    PHP Code:
    $string1 "In today’s high speed"// please take not of the inverted commas 
    PHP Code:
    $string1 "In today's high speed";// please take not of the inverted commas 


    When i insert the two into the database with the mysql_real_escape function
    The first string is not escaped while but gives me some unknown texts

    while the second string is escaped correctly, is there difference between the two inverted commas?

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by franzlin2010 View Post
    while the second string is escaped correctly, is there difference between the two inverted commas?
    Yes. The second one, ' is a special character where SQL is concerned, hence needs to be escaped. The first is not, so will be inserted as is. The unknown text you are seeing is most likely its ASCII value or suchlike:

    http://www.asciitable.com/

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    the first one is the "right single quotation mark". you need UTF-8 to display it correctly.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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