Jump to content

Anyone have a big array of character conversions?


svivian

Recommended Posts

Hey guys, I'm new to this forum (but not to PHP). I would like to know if anyone has a nice array of ASCII character conversions. The kind of thing I'm looking for is like that provided at http://www.phpfreaks.com/quickcode/Latin1-converter/612.php but more extensive.

 

The idea is that if, say, a user submits a form with something they typed in Word, then all apostrophes and quotation marks are likely to be the curly ones. Same goes for hyphens, they are the 'long' versions. What I would like to do is to convert all these characters to nice, standard ASCII characters, eg:

“hello” -> "hello" (or probably "hello").

All characters that don't have a standard ASCII equivalent would just be converted to &#...; syntax.

 

Does anyone happen to have a list of these kind of conversions (preferably in PHP array format)?

 

Note: I'm not asking anyone to write a whole conversion script for me, I am perfectly capable of doing so myself. I'm just looking for a conversion table. Also, if no one has one already done, no need to write it for me...

www.php.net/htmlentities have you checked out that function?

 

If that does not work, probably the best way to get rid of those stupid smart quotes is find the www.php.net/char  number for it and than use str_replace to replace that specific char(). If you are wondering what is all available and to what extent using char you can do this:

 

<?php
for ($i=0;$i<256;$i++) {
     echo $i . ' = ' . char($i) . '<br />';
}
?>

 

or http://www.asciitable.com/

 

may help too.

Yes, I am aware of that function. The problem with that is it will convert “hello” to &#147;hello&#148; and not "hello" or "hello" as required.

 

It's a bit picky I know, but I want to convert each non-ASCII character to a similar ASCII character if there is one and not to just &#...;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.