Created
January 3, 2015 13:07
-
-
Save OjosAlertaAC/f009652a5cd5f7954c8b to your computer and use it in GitHub Desktop.
Fix garbage in mybb conversion for spanish forums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Alfonso Orozco Aguilar for Ojos Alerta AC - ojosalerta.org | |
Using LGPL 2.0 Exclusively | |
https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html | |
Original version: 04/dec/2013 | |
Comments to : github(nospam)@alfonsoorozco.com | |
The purpose of this snippet is change special chars in mybb forums to normal | |
chars (no UTF8-ed). Was used by me for a massive merge operations of mybb | |
forums in spanish. Can be altered for topics table, but i need mybb_posts. | |
As always , get backup first | |
*/ | |
mysql_connect('localhost','databaseuser','databasepassword') or die ("error in password to connect server"); | |
echo "<li>connected server"; | |
mysql_select_db ('databasename') or die ('cant connect to database'); | |
echo "<li>connected database"; | |
// altering database posts | |
$result=mysql_query("Select pid,message from mybb_posts") or die ("Cant open posts table"); | |
while ($row = mysql_fetch_object($result)) { | |
$pid=$row->pid; | |
$orm=$row->message; | |
$newm=spanish_change($orm); | |
if ($newm<>$orm) { // begin spanish change special chars | |
$newm=addslashes($newm); | |
mysql_query("UPDATE mybb_posts set message='$newm' where pid='$pid'") or die ("error :".mysql_query()); | |
echo "<li>Changing $pid"; | |
} // end change special chars | |
} | |
mysql_free_result($result); | |
function spanish_change($text){ | |
$pass=$text; | |
$pass=str_replace("á","á",$pass); | |
$pass=str_replace("é","é",$pass); | |
$pass=str_replace("Ã*","í",$pass); | |
$pass=str_replace("ó","ó",$pass); | |
$pass=str_replace("ú","ú",$pass); | |
$pass=str_replace("ñ","ñ",$pass); | |
$pass=str_replace("ë","ë",$pass); | |
$pass=str_replace("ü","ü",$pass); | |
$pass=str_replace("»","»",$pass); | |
$pass=str_replace("«","«",$pass); | |
$pass=str_replace("©","©",$pass); | |
$pass=str_replace("®","®",$pass); | |
$pass=str_replace("â„¢","™",$pass); | |
$pass=str_replace("â??",chr(34),$pass); | |
$pass=str_replace("Ãa","ía",$pass); | |
$pass=str_replace("Ãa","ía",$pass); | |
$pass=str_replace("Ãr","ír",$pass); | |
$pass=str_replace("Ã","í",$pass); | |
return ($pass); | |
} // spanish_change | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment