Get Cyrillic words from JSON string in PHP? JSON string is unstructured and any type.
Example:
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Вилен", "lastName":"Авангард"},
{"firstName":"Станислав", "lastName":"Андрей"}
]}
Output:
Вилен Авангард Станислав Андрей
If you need to do with regular expression the check the online script here
For general purpose:
You need to check the firstName
or lastName
is english or not, if not then store them in an array and at the end just implode them as the result demand.
$json = '{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Вилен", "lastName":"Авангард"},
{"firstName":"Станислав", "lastName":"Андрей"}
]}';
$arr = json_decode($json, true);
$out = array();
foreach($arr['employees'] as $value){
if(strlen($value['firstName']) != mb_strlen($value['firstName'], 'utf-8'))
$out[] = $value['firstName'];
if(strlen($value['lastName']) != mb_strlen($value['lastName'], 'utf-8'))
$out[] = $value['lastName'];
}
echo implode(" ", $out); //Вилен Авангард Станислав Андрей
Note: You need mbstring php module installed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.