简体   繁体   English

从 PHP 中的 json 字符串获取西里尔字母?

[英]get cyrillic words from json string in PHP?

Get Cyrillic words from JSON string in PHP?从 PHP 中的 JSON 字符串获取西里尔字母? JSON string is unstructured and any type. JSON 字符串是非结构化的任何类型。

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.您需要检查firstNamelastName是否为英文,如果不是,则将它们存储在一个数组中,最后将它们作为结果要求内爆。

$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.注意:您需要安装 mbstring php 模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM