Jump to content

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 &#...;

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.