/ Published in: PHP
                    
                                        
Sometimes a legacy database will have HTML entities stored in it.
This function converts them. Note that this function assumes you have a database abstraction layer, and may need to be modified to connect to YOUR database.
                This function converts them. Note that this function assumes you have a database abstraction layer, and may need to be modified to connect to YOUR database.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
$connector = new DbConnector(); // Change to YOUR db connection class.
$query = "SET NAMES 'utf8'"; // Put MySQL connection into UTF8 mode.
$connector->query($query); // Change to YOUR db query execution method.
foreach($tables as $table)
{
$sql = "SELECT * FROM {$table}";
$rows = $connector->query($sql); // Change to YOUR db query execution method.
{
foreach($row as $key => $data)
{
$new[$key] = $connector->escapeString(html_entity_decode($data, ENT_QUOTES, 'UTF-8')); // Change to YOUR db escape execution method.
}
$new_string = "";
$i = 0;
foreach($new as $new_key => $new_data)
{
if($i > 0) { $new_string.= ", "; }
$new_string.= $new_key . "='" . $new_data . "'";
$i++;
}
$sql = "UPDATE {$table} SET " . $new_string . " WHERE id='" . $row['id'] . "'";
$connector->query($sql); // Change to YOUR db query execution method.
}
}
?>
URL: http://stackoverflow.com/questions/2838245/how-to-remove-htmlentities-values-from-the-database
Comments
 Subscribe to comments
                    Subscribe to comments
                
                