Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 4 of 4

Thread: Help on PHP,SQL special char encoding

  1. #1

    Help on PHP,SQL special char encoding

    I have a problem on displaying "" when I used javascript(ajax) to send to my callback url I used

    escape(str)

    then the php callback file will save it to mySQL, the field data type is in VARCHAR, when I look into the phpMyAdmin, the value is okay, it is "" but when I retrieve it and display it, it shows diamond symbol with a "?" on it.

    do I have to use a code to return it to "" ?
    I already used urlencode & urldecode. But it displays a more complicated value.

    I have two displays. I retrieved the variable and display it on html/XML using ajax. And I also use the same variable displayed in a PDF file format. The PDF file displayed "", but the HTML/XML displays the strange "?" value.

    Thanks for the help.

  2. #2
    It displays this character �
    Last edited by epoy08; September 20th, 2009 at 06:57 AM.

  3. #3
    In ur code there might be meta problem

    use <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> this

    then also u have problem then using htmlentities convert that content and save in DB.

    then using Decoding HTML entities (html_entity_decode)

    we can get the value;
    PHP Code:
    <?php

    $orig 
    "I'll \"walk\" the <b>dog</b> now";

    $a htmlentities($orig);

    $b html_entity_decode($a);

    echo 
    $a// I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

    echo $b// I'll "walk" the <b>dog</b> now

    ?>
    You can try this code.



  4. #4
    jwilliam's Avatar
    476
    posts
    An intellectual carrot!
    benivolent is right. I personally think (with modern browsers) you should always use utf-8 encoding.

    If you set your encoding to UTF-8 in your headers, ensure your database is using UTF-8 encoding and... if you're using mysql call "SET NAMES 'utf-8'" before pulling data from the database... you'll pretty much ensure that any character you print to the screen will display properly.

    You also may want to check out this link:

    http://xkr.us/articles/javascript/encode-compare/

    the javascript escape() function should rarely be used.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012