Page 1 of 1
removing wierd talking marks
Posted: Mon Nov 10, 2003 12:39 am
by Castles
Hi, I have written a little program that inserts information into a sql database and then reads from it. When it is finished my client will hopefully copy and paste text into this text box and then the database will automatically update etc.. my problem is, when the user copies from word to the text box (its actually a flash text field) it copies wierd apostraphes... these things ... ''''', they are curly word ones.. when it gets inserted into the database, everything works fine, but when it is read, it oupts "puts it, doesn’t let their" which is meant to be "puts it, doesn't let their" I am using addslashes and strip slashes to read from the database etc.. is there a way to remove these funny apostraphes?
Posted: Mon Nov 10, 2003 3:39 am
by twigletmac
Word is a bug bear of ours with it's curly quotes and elongated dashes

. To get around this problem I wrote the following function:
Code: Select all
function bbcode_replace_msword_entities($text)
{
$msword['from'] = array('’', '“', '”', '“', '”', '–', '’', '‘');
$msword['to'] = array('''', '"', '"', '"', '"', '-', '''', '''');
$text = str_replace($msword['from'], $msword['to'], $text);
return $text;
} // end func
it's simple but it gets rid of that irritating stuff and I add new entity numbers when I find them.
Mac
Posted: Mon Nov 10, 2003 5:05 pm
by Castles
hmm.. i have tried that but it is still returning the wierd talking marks.. If I view the source it is coming up as <P>‘</P> when it really should be.. <P>'</P>
The code I added tomy page was:
Code: Select all
<?php
//clean up code if it has funny word copy paste stuff
$content = replace_msword_entities($content);
//remove funny word characters
function replace_msword_entities($text)
{
$msword['from'] = array('’', '“', '”', '“', '”', '–', '’', '‘', '‘');
$msword['to'] = array('''', '"', '"', '"', '"', '-', '''', '''','''');
$text = str_replace($msword['from'], $msword['to'], $text);
return $text;
}
?>
Posted: Tue Nov 11, 2003 2:57 am
by twigletmac
What I tend to do if there's a character that won't shift, is cut it and add it to the end of the $msword['from'] array and what it should be to the end of the $msword['to'] array - sometimes different fonts do things differently.
What do you get in the source for the curly quote if you do:
Code: Select all
$content = replace_msword_entities(htmlentities($content));
BTW, on a side note, you shouldn't need stripslashes() to read from the database, only addslashes() to put things in.
Mac
Posted: Wed Nov 12, 2003 10:29 am
by Castles
ahh, I see.. thanks for your help.. what i found out was.. because I was getting the content variable from a flash file it was sending a unicode value for the apostraphe..so I wrote a search and replace function that made flash send a non unicode apostraphe and it all worked..
so basically the user will now copy from word into the flash form and then the form will then send it to the php page which will then clean up any yucky code.
The only prob I then had was flash was gerating this ''' for the apostraphe in html code.. and i worked out the php page won't display this like a html page.. yeah.. so just added it to your funtion..
Its all working, thanks for your help... as far as running:
Code: Select all
<?php $content = replace_msword_entities(htmlentities($content));
?>
.. it didn't return anything differently..