# Replacing Special Characters

**URL:** <https://www.phphelp.com/t/replacing-special-characters/19350>\
**Category:** General PHP Help\
**Created:** [January 15, 2013, 6:09am UTC](https://www.phphelp.com/t/replacing-special-characters/19350 "2013-01-15T06:09:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaditya](https://www.phphelp.com/letter_avatar_proxy/v4/letter/v/65b543/32.png) [@vaditya](https://www.phphelp.com/u/vaditya)\
**Post date:** [January 15, 2013, 6:09am UTC](https://www.phphelp.com/t/replacing-special-characters/19350/1 "2013-01-15T06:09:43Z")

</div>

I run a file with the following code to replace special characters in mysql database. But nothing happened. Can anyone help me to solve this problem.

\<?php mysql\_connect("localhost", "dbuser", "password") or die("Connection Failed"); mysql\_select\_db("dbname")or die("Connection Failed"); $sql = "UPDATE content set title = replace(title,'‘', '\'')"; $sql = "UPDATE content set title = replace(title,'’', '\'')"; $sql = "UPDATE content set title = replace(title,'”', '\"')"; $sql = "UPDATE content set title = replace(title,'“', '\"')"; $sql = "UPDATE content set title = replace(title,'–', '-')"; $sql = "UPDATE content set title = replace(title,'…', '...')"; ?\>

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [January 15, 2013, 6:26am UTC](https://www.phphelp.com/t/replacing-special-characters/19350/2 "2013-01-15T06:26:56Z")

</div>

That should work. I have a list of my own:

```auto
UPDATE `table` SET `column` = REPLACE(`column`,'’','\'');
UPDATE `table` SET `column` = REPLACE(`column`,'”','\"');
UPDATE `table` SET `column` = REPLACE(`column`,'“','\"');
UPDATE `table` SET `column` = REPLACE(`column`,'–','-');
UPDATE `table` SET `column` = REPLACE(`column`,'…','...');
UPDATE `table` SET `column` = REPLACE(`column`,'Ã¡','á');
UPDATE `table` SET `column` = REPLACE(`column`,'Ã©','é');
UPDATE `table` SET `column` = REPLACE(`column`,'í©','é');
UPDATE `table` SET `column` = REPLACE(`column`,'Ã³','ó');
UPDATE `table` SET `column` = REPLACE(`column`,'íº','ú');
UPDATE `table` SET `column` = REPLACE(`column`,'Ãº','ú');
UPDATE `table` SET `column` = REPLACE(`column`,'Ã±','ñ');
UPDATE `table` SET `column` = REPLACE(`column`,'í‘','Ñ');
UPDATE `table` SET `column` = REPLACE(`column`,'Ã','í');
UPDATE `table` SET `column` = REPLACE(`column`,'â€™','\'');
UPDATE `table` SET `column` = REPLACE(`column`,'â€¦','...');
UPDATE `table` SET `column` = REPLACE(`column`,'â€“','-');
UPDATE `table` SET `column` = REPLACE(`column`,'â€"','-');
UPDATE `table` SET `column` = REPLACE(`column`,'â€œ','"');
UPDATE `table` SET `column` = REPLACE(`column`,'â€','"');
UPDATE `table` SET `column` = REPLACE(`column`,'â€˜','\'');
UPDATE `table` SET `column` = REPLACE(`column`,'â€¢','-');
UPDATE `table` SET `column` = REPLACE(`column`,'â€¡','c');
```

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [January 15, 2013, 6:33am UTC](https://www.phphelp.com/t/replacing-special-characters/19350/3 "2013-01-15T06:33:55Z")

</div>

Oh… you are not executing your queries in that code? You should have a mysql\_query($sql) after each update line.

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [January 15, 2013, 7:26pm UTC](https://www.phphelp.com/t/replacing-special-characters/19350/4 "2013-01-15T19:26:14Z")

</div>

Please use the thread instead of messages 🙂

Trying adding the or die to your mysql\_query to verify there are no issues there.

[php]  
$query = mysql\_query(“UPDATE phpnews\_news set subject = replace(subject,’…’, ‘…’)”)or die(mysql\_error());[/php]

---

<div class="post-metadata">

**Author:** ![mohamed1010](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/278dde/32.png) [@mohamed1010](https://www.phphelp.com/u/mohamed1010)\
**Post date:** [January 15, 2013, 8:32pm UTC](https://www.phphelp.com/t/replacing-special-characters/19350/5 "2013-01-15T20:32:36Z")

</div>

save data in database with this function … it will clear all unnecessary special charachter may cause error  
also you can retrieve data with same function

for example

$value = mysql\_real\_escape\_string($\_POST[‘fieldname’]) ;  
mysql\_query(" insert into tablename (columnname)value ( ‘".$value."’ ) ");
