weird characters while i display query results.

Discussion in 'PHP' started by jasvarghese, Jan 11, 2009.

  1. #1
    Hello All

    While i print a query from wordpress to my site it shows weird characters
    Something like:
    What�s With the Cutbacks?
    The original form is What’s With the Cutbacks?

    Im not sure why its happening like this.

    Can anybody pls tell me why its happening and how to resolve it.
    All helps would be greatly appreciated.
    Thanks
     
    jasvarghese, Jan 11, 2009 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    You used a ' from Word or some other word processor so UTF replaces it with that char.

    Always paste your text to something like notepad2 and replace all " ' with that charset before you insert it into a database or a UTF text page.
     
    Colbyt, Jan 11, 2009 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Wrong charset I'd assume, what charset is in use and what header is being sent?
     
    Danltn, Jan 11, 2009 IP
  4. jasvarghese

    jasvarghese Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Im facing the problem after retrieving the data from database. But the same text is showing well in phpMyAdmin, not in my page.

    My title is something like this : "What's... "

    its not able to show ' in my page, rest of the places its shows well. Im wondering if thr is anything wrong with my page??....
     
    jasvarghese, Jan 11, 2009 IP
  5. jasvarghese

    jasvarghese Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    You are right, but How to avoid the character misprinting if user enters the details by copying from word?

    Is ther any way out for that?
     
    jasvarghese, Jan 11, 2009 IP
  6. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #6
    I imagine it can be done but it must not be real easy else I would not see so many posts here at DP with those blocks in the titles.

    As speculation only since the topic is more advanced than my PHP skills, I would assume you could sanitize the input using some character replacement feature of PHP.
     
    Colbyt, Jan 11, 2009 IP
  7. jasvarghese

    jasvarghese Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    i think its happening with Wordpress even.. :(
     
    jasvarghese, Jan 11, 2009 IP
  8. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8
    Using UTF-8 would be a nice idea in order to avoid those characters to appear. Remember you have to do the following:
    - Your server need to have in you httpd.conf apache file: AddDefaultCharset UTF-8 (if you use apache),
    - Your webpages headers need to have a META tag defined with charset=UTF-8,
    - Finally, your webpage files need to be saved with an editor that will allow you to change the file encoding to UTF-8. Eclipse allows you to do this perfectly.

    Only after meeting those 3 requirements, your pages will show you data with the right special characters.
     
    webrickco, Jan 12, 2009 IP
  9. jasvarghese

    jasvarghese Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #9
    I understood first 2 options, Can you pls give me some basic idea for the 3rd option that is "Finally, your webpage files need to be saved with an editor that will allow you to change the file encoding to UTF-8. Eclipse allows you to do this perfectly."

    Thanks a lot for the good efforts. :)
     
    jasvarghese, Jan 14, 2009 IP