1

Possible Duplicate:
UTF-8 all the way through

I want submit text from text box in a form to a table in MYSQL which in turn show text in the post on website but there is a special quot ‘ in place of this ' which get converted into Â

Please tell how to submit data with simple text without showing these characters

I have already used

urldecode ( string $str ) , str_replace () 

Here is my code

$description = mysql_real_escape_string(htmlspecialchars(utf8_encode($_REQUEST['txtDescription'])));
Community
  • 1
  • 1
i.jolly
  • 61
  • 2
  • 9
  • Is your web page rendering in UTF-8 ? – idstam Dec 23 '11 at 10:29
  • both apostrophes on line 2 are different in ASCII try on this site http://textmechanic.com/ASCII-Hex-Unicode-Base64-Converter.html – i.jolly Dec 23 '11 at 10:30
  • In Firefox you can right-click the page and select 'View Page Info' – idstam Dec 23 '11 at 10:34
  • @idstam ya its saying so Encoding :UTF-8 – i.jolly Dec 23 '11 at 10:36
  • 1
    At first remove the `utf8_encode()` from your code, then try again. – hakre Dec 23 '11 at 10:50
  • @hakre done ! still same – i.jolly Dec 23 '11 at 10:57
  • Well for the data that is already in your database, this won't change a thing. You need to convert and/or delete the existing data first. If you've done that, edit your question accordingly to the change you made in your code. – hakre Dec 23 '11 at 11:04
  • Everything needs to be in the same charset, so if you're planning on using UTF-8, then your database must be UTF-8, the PHP script must be saved as a UTF-8 file, and so must the HTML. If anything is a different charset you'll find yourself in charset hell. (If everything is in UTF-8 then you probably don't need to re-encode the string as UTF-8) – GordonM Dec 23 '11 at 11:45

3 Answers3

2

You should call SQL code

SET NAMES utf8

before DML or SELECT.

Then make sure your HTML is utf8 encoded:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
rkosegi
  • 14,165
  • 5
  • 50
  • 83
0

Today I found answer of my question by doing deep study on net

Strange special characters shown in my question are shown due to meta tags

so when we add UTF-8 meta then such type of characters are show so here is the solution

Replace below code on your webpage

<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />

with

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
i.jolly
  • 61
  • 2
  • 9
0

Showing all code required to insert, retrieve and showing on webpage without showing any special characters

During submit of text to MYSQL table using query use below code

$description = $_REQUEST['txtDescription'];
$description = mysql_real_escape_string($description); 

$description variable will be used in SQL insert query

During Retrieve and Showing of text from MYSQL table use below code

<?php print(str_replace("\n", "<br />", $row['tDescription']));?>

And also follow the 1 Answer above to show it properly

i.jolly
  • 61
  • 2
  • 9