iPixel Posted July 28, 2009 Share Posted July 28, 2009 So i've got these Geniuses that instead of entering let's say ® into the database they paste from word like so ®. But when i pull that specific into from the table it returns as a weird looking [] thing. Is it possible with php to get it to read the database table with the ®'s inside it? Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/ Share on other sites More sharing options...
fooDigi Posted July 28, 2009 Share Posted July 28, 2009 i put together this function to replace word characters with their html entity equivalent, respectively... you can add more chr()'s and their replacements if you know the character codes... this will replace some of msword's characters, i added 174 which i think is the registered trademark, might want to double check... function replace_word($str) { $return = ''; $search = array(chr(145),chr(146),chr(147),chr(148),chr(150),chr(151),chr(174)); $replace = array("'","'",'"','"','–','–','®'); $return = str_replace($search,$replace,$str); return $return; } Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/#findComment-885219 Share on other sites More sharing options...
taquitosensei Posted July 28, 2009 Share Posted July 28, 2009 microsoft word uses UTF-8 you'll have to add this at the top of your page header('Content-Type: text/plain; charset=utf-8'); Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/#findComment-885220 Share on other sites More sharing options...
iPixel Posted July 28, 2009 Author Share Posted July 28, 2009 The UTF-8 code didnt work, i'll try the function and see how it goes. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/#findComment-885226 Share on other sites More sharing options...
fooDigi Posted July 28, 2009 Share Posted July 28, 2009 i think my function is flawed... sorry... this may work better though and is more simple... echo htmlentities(utf8_decode($str)); Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/#findComment-885228 Share on other sites More sharing options...
fooDigi Posted July 28, 2009 Share Posted July 28, 2009 ahh, now it works. i modified my function with some help of some code i found and modified... <? function replace_word($str) { $return = ''; $final = ''; $search = array(chr(145),chr(146),chr(147),chr(148),chr(150),chr(151),chr(169),chr(174)); $replace = array("'","'",'"','"','–','–','©','®'); $return = str_replace($search,$replace,$str); $ret_array = preg_split('//', $return); foreach ($ret_array as $val) { if (ord($val) < 128) $final .= $val; } return $final; } echo replace_word("© copyright and ® registered"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/#findComment-885239 Share on other sites More sharing options...
iPixel Posted July 30, 2009 Author Share Posted July 30, 2009 This function worked awesome Thanks! PS: using that UTF-8 line makes the page go BOOOM on mac's via safari / ff. Quote Link to comment https://forums.phpfreaks.com/topic/167833-solved-reading-speical-characters-from-mysql-db/#findComment-887111 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.