Jump to content

[SOLVED] Reading speical characters from MySQL DB.


iPixel

Recommended Posts

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?

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.