代码之家  ›  专栏  ›  技术社区  ›  James

如何在PHP中计算文本语句中的空格

  •  14
  • James  · 技术社区  · 16 年前

    example: hi how are you?
    
    spaces: 3
    

    4 回复  |  直到 4 年前
        1
  •  38
  •   gahooa    16 年前

    substr_count($text, ' ');
    
        2
  •  1
  •   jimyi    16 年前

    preg_match_all .

    $numSpaces = preg_match_all('/[ ]/', $testStr, $matches);
    
        3
  •  1
  •   nikc.org    16 年前
    $arr = count_chars($str,1);
    echo $arr[32];