svivian Posted May 28, 2007 Share Posted May 28, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/53274-anyone-have-a-big-array-of-character-conversions/ Share on other sites More sharing options...
per1os Posted May 28, 2007 Share Posted May 28, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/53274-anyone-have-a-big-array-of-character-conversions/#findComment-263268 Share on other sites More sharing options...
svivian Posted May 28, 2007 Author Share Posted May 28, 2007 Yes, I am aware of that function. The problem with that is it will convert “hello” to “hello” 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 &#...; Quote Link to comment https://forums.phpfreaks.com/topic/53274-anyone-have-a-big-array-of-character-conversions/#findComment-263269 Share on other sites More sharing options...
svivian Posted May 28, 2007 Author Share Posted May 28, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/53274-anyone-have-a-big-array-of-character-conversions/#findComment-263561 Share on other sites More sharing options...
kenrbnsn Posted May 29, 2007 Share Posted May 29, 2007 Take a look at the article Convert Smart Quotes with PHP Ken Quote Link to comment https://forums.phpfreaks.com/topic/53274-anyone-have-a-big-array-of-character-conversions/#findComment-263569 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.