I am using these code to check if a string is in English or not.
<?php
$string="で書くタッチイベント (フ";
if(!preg_match('/[^\W_ ] /',$string)) {
echo "Please enter English words only:(";
} else {
echo "OK, English Detected!";
}
?>
It cant provide perfect result because string like "some english text で書くタッチイベント (フ"
this also detects as English language, any idea?
Try this (please note you need mbstring php module installed):
<?php
$string="で書くタッチイベント (フ";
if(strlen($string) != mb_strlen($string, 'utf-8'))
{
echo "Please enter English words only:(";
}
else {
echo "OK, English Detected!";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With