Reputation: 17383
there are many questions on stackoverflow that them say if a string contains only english letters. but I would like to know how can I to check if a string has english letters :
ex:
$string="で書くタッチイベント B A(フ";
if(??? $string)
//this string has some english letters .
Upvotes: 2
Views: 134
Reputation: 774
Use preg_match()
Example :-
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>
wrt question it will be like :-
<?php
$string = "で書くタッチイベント B A(フ";
$pattern = '/[a-zA-Z]/';
preg_match($pattern, $string, $matches);
print_r($matches);
?>
Upvotes: 4