doni
doni

Reputation: 21

strings with only ascii characters php

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

Upvotes: 1

Views: 2698

Answers (2)

Saul
Saul

Reputation: 18041

<?php

echo preg_replace('/[^(\x20-\x7F)]*/', '', 'Standard ASCII and some gärbägè');

?>

Upvotes: 5

Mormegil
Mormegil

Reputation: 8071

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.

Upvotes: 3

Related Questions