harley1387 Posted January 16, 2008 Share Posted January 16, 2008 Does anyone know how to replace MS Word characters for text that is copied/pasted (character ranges 128 -> 159) without using the chr function? In a previous post http://www.phpfreaks.com/forums/index.php/topic,177458.0.html, PFMaBiSmAd mentioned: chr() is only valid for ASCII characters. ASCII characters are only defined for 0 - 127. Using chr() for values greater than 127 is at your own risk. Found this function elsewhere...but it uses chr: function htmlfriendly($var,$nl2br = false){ $chars = array( 128 => '€', 130 => '‚', 131 => 'ƒ', 132 => '„', 133 => '…', 134 => '†', 135 => '‡', 136 => 'ˆ', 137 => '‰', 138 => 'Š', 139 => '‹', 140 => 'Œ', 142 => 'Ž', 145 => '‘', 146 => '’', 147 => '“', 148 => '”', 149 => '•', 150 => '–', 151 => '—', 152 => '˜', 153 => '™', 154 => 'š', 155 => '›', 156 => 'œ', 158 => 'ž', 159 => 'Ÿ'); $var = str_replace(array_map('chr', array_keys($chars)), $chars, htmlentities(stripslashes($var))); if($nl2br){ return nl2br($var); } else { return $var; } } Quote Link to comment https://forums.phpfreaks.com/topic/86326-death-to-microsoft-word-copypaste-in-form-fields/ Share on other sites More sharing options...
harley1387 Posted January 17, 2008 Author Share Posted January 17, 2008 Came across the following two ideas...but neither are ideal. There has to be a ready-made PHP function as I can't be the only one with this problem?!?! Provides clean code for MS Word text that is copied/pasted: http://www.fckeditor.net/ "onpaste" disables pasting into a field...but not sure about the compatibility -- and it's a complete hack: <input type="text" name="email" onpaste="event.returnValue=false;"> Quote Link to comment https://forums.phpfreaks.com/topic/86326-death-to-microsoft-word-copypaste-in-form-fields/#findComment-441739 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.