fohanlon Posted September 9, 2011 Share Posted September 9, 2011 Hi Guys After searchign the web and forums I still cannot find a suitable solution for my problem. I have a textarea. Say the user copies in from MS Word the following: “!"£$%^&*()@'#:;/?!"£$%^&*()@'#:;/?!"£$%^&*()@'#:;/?!"£$%^&*()@'#:;/?!"£$%^&*()@'#:;/?!"£$%^&*()@'#:;/?!"£$%^&*()@'#:;/?!"£$!"£$%^&” Before I save it to a database I want to clean it up i.e replace or remove the  I have read that the  will take up 2 characters. Also, if I could also replace MS Word single and double quotes that would be great. I was looking at the str_replace with the Chr() function but to no use. Thanks for reading. Regards Fergal. Quote Link to comment https://forums.phpfreaks.com/topic/246813-ms-word-special-character-replacement/ Share on other sites More sharing options...
WebStyles Posted September 9, 2011 Share Posted September 9, 2011 str_replace works for me, as long as you have the correct encoding. I did this little page to test it: <?php mb_internal_encoding("UTF8"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> </head> <body> <form action="" method="post"> <textarea name="inputText"></textarea> <input type="submit"> </form> <br /> <?php if(isset($_POST['inputText'])){ $text = $_POST['inputText']; echo stripslashes(str_replace("Â","A",str_replace("“","",str_replace("”","",$text)))); } ?> </body> </html> it outputs the same, with Â's converted to A and word's curly quotes removed. Note: I used stripslashes just to see the output because the single quotes were escaped, but you definitely want to use something like mysql_real_eacape_string before inserting something like that into a database. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/246813-ms-word-special-character-replacement/#findComment-1267515 Share on other sites More sharing options...
requinix Posted September 9, 2011 Share Posted September 9, 2011 The  is not some magic letter. If they tried copying more exotic characters you'd find something else instead of that Â. Make sure your HTML page is in UTF-8 encoding. Make sure your database tables are in UTF-8 encoding. With those two set you shouldn't have to alter any data. Worst and unlikely case, the pasted text will be double-encoded, in which case you need to decode it once to get the original data. Quote Link to comment https://forums.phpfreaks.com/topic/246813-ms-word-special-character-replacement/#findComment-1267516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.