suchen

Heim  >  Fragen und Antworten  >  Hauptteil

php 数组和字符串的问题

请教一个php数组和字符串的转换问题。我有如下一个字符串:

["approval","bbcode","emoji","english","flags","likes","simplified-chinese"]

除了使用explode函数分割处理外,有没有其他的快速将其转换为数组的方法。

PHP中文网PHP中文网2777 Tage vor978

Antworte allen(2)Ich werde antworten

  • 迷茫

    迷茫2017-04-10 16:23:36

    $array = json_decode('["approval","bbcode","emoji","english","flags","likes","simplified-chinese"]', true);

    Antwort
    0
  • 迷茫

    迷茫2017-04-10 16:23:36

    可以用正则,但效率应该低一些

    $str = '"approval","bbcode","emoji","english","flags","likes","simplified-chinese"';
    preg_match_all('/\".[^,]*\"/',$str,$out);
    print_r($out);
    

    也可以自己写c扩展,效率应该和explode差不太多

    Antwort
    0
  • StornierenAntwort