dgruetter Posted July 19, 2010 Share Posted July 19, 2010 Hi, I am new to this board. I have a problem when inserting text into a mysql database from a text box. When the test gets inserted into the table It is turning any Microsoft quotes into junk characters. I have created a few helper functions: clean_string, mysql_prep to prepare the clean and prepare the code to be inserted but I am afraid It might be hurting rather than fixing it. Here is a snippit: <?php print "<input name=\"vendor_info\" type=\"hidden\" value=\"".htmlspecialchars($vendor_info)."\">"; ?> function mysql_prep( $value ) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists( "mysql_real_escape_string" ); if ( $new_enough_php ) { //undo effects of magic quotes $value = mysql_real_escape_string( $value ); } else { //If magic quotesw are not active add slashes manually if (!$magic_quotes_active) { $value = addslashes( $value ); } } return $value; } function clean_string ($str) { $str = str_replace(chr(130), ',', $str); // baseline single quote $str = str_replace(chr(131), 'NLG', $str); // florin $str = str_replace(chr(132), '"', $str); // baseline double quote $str = str_replace(chr(133), '...', $str); // ellipsis $str = str_replace(chr(134), '**', $str); // dagger (a second footnote) $str = str_replace(chr(135), '***', $str); // double dagger (a third footnote) $str = str_replace(chr(136), '^', $str); // circumflex accent $str = str_replace(chr(137), 'o/oo', $str); // permile $str = str_replace(chr(138), 'Sh', $str); // S Hacek $str = str_replace(chr(139), '<', $str); // left single guillemet $str = str_replace(chr(140), 'OE', $str); // OE ligature $str = str_replace(chr(145), "'", $str); // left single quote $str = str_replace(chr(146), "'", $str); // right single quote $str = str_replace(chr(147), '"', $str); // left double quote $str = str_replace(chr(148), '"', $str); // right double quote $str = str_replace(chr(149), '-', $str); // bullet $str = str_replace(chr(150), '-', $str); // endash $str = str_replace(chr(151), '--', $str); // emdash $str = str_replace(chr(152), '~', $str); // tilde accent $str = str_replace(chr(153), '(TM)', $str); // trademark ligature $str = str_replace(chr(154), 'sh', $str); // s Hacek $str = str_replace(chr(155), '>', $str); // right single guillemet $str = str_replace(chr(156), 'oe', $str); // oe ligature $str = str_replace(chr(159), 'Y', $str); // Y Dieresis return $str; } $vendor_info = clean_string($_POST['vendor_info']); $vendor_info = mysql_prep($_POST['vendor_info']); $sql = "INSERT INTO $table_name ( vendor_id..... Please be gentle, I am still learning PHP and I am far from an expert. Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/208237-mysql-replacing-microsoft-word-quotes-with-junk-characters/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.