I have set of strings where some of them are made of non-ascii characters. How do I get strings with only ascii characters using a php script.
Thanks a lot in advance for any guidance..
I have set of strings where some of them are made of non-ascii characters. How do I get strings with only ascii characters using a php script.
Thanks a lot in advance for any guidance..
<?php
echo preg_replace('/[^(\x20-\x7F)]*/', '', 'Standard ASCII and some gärbägè');
?>
^ there and assumed the hex codes were for things out of printable range. will blame it on lack of coffee :) thanks for setting me straight.Probably the easiest option is to use the iconv function (if the iconv extension is available), using either the //IGNORE or //TRANSLIT option (see the documentation), if the behavior suits your needs.
a^Xb (^X being a control char). iconv will never remove it, because ^X is not part of any encoding it understands. it used to remove it with //IGNORE, but if you follow the bugs on the top comment for iconv you will see that is not the case anymore.