user56620
user56620

Reputation: 21

How to deny foreign alphabets in utf-8 in PHP 5.x (symfony)?

I have to disable chinese, japanese, cyrillic (and so on) alphabets to be entered by users in my website, at validation time (only server side validation). At the same time I want all latin accented characters to be allowed. I use symfony 1.1 and PHP 5.2, using utf-8, of course. Any hint?

Upvotes: 2

Views: 546

Answers (2)

TravisO
TravisO

Reputation: 9540

If you need to pick and choose, you won't be able to avoid using regex and/or creating a list of allowed characters.

Yes this is not easy nor quick, but if you want to nit-pick characters, you might need to get specific.

Upvotes: 0

troelskn
troelskn

Reputation: 117457

You can always convert to latin1 and then back again. That would discard any non latin1 characters. Eg.:

$str = utf8_encode(utf8_decode($str));

I wonder why you want this in the first place though?

Upvotes: 1

Related Questions