Replacing Special Characters

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,'…', '...')"; ?>

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

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');

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

Please use the thread instead of messages :slight_smile:

Trying adding the or die to your mysql_query to verify there are no issues there.

$query = mysql_query(“UPDATE phpnews_news set subject = replace(subject,’…’, ‘…’)”)or die(mysql_error());[/php]

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."’ ) ");

Sponsor our Newsletter | Privacy Policy | Terms of Service