我正在試驗explode()失敗的東西,所以我想嘗試其他的東西。如果我有一個字符串,我怎麼能算在它的字符被假設的數量comma
在,
計數X字符的數量
Q
計數X字符的數量
1
A
回答
3
substr_count($text, ',');
1
您可以使用count_chars
例從PHP手冊:
$data = "Two Ts and one F.";
foreach (count_chars($data, 1) as $i => $val) {
echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
}
輸出(codepad):
There were 4 instance(s) of " " in the string.
There were 1 instance(s) of "." in the string.
There were 1 instance(s) of "F" in the string.
There were 2 instance(s) of "T" in the string.
There were 1 instance(s) of "a" in the string.
There were 1 instance(s) of "d" in the string.
There were 1 instance(s) of "e" in the string.
There were 2 instance(s) of "n" in the string.
There were 2 instance(s) of "o" in the string.
There were 1 instance(s) of "s" in the string.
There were 1 instance(s) of "w" in the string.
+0
不要忘記檢查'isset($結果[」, '])'如果不能保證逗號在字符串中(結果數組中沒有逗號的可能性) – 2010-12-15 21:29:06
相關問題
- 1. Java在指定的字符串中計算x的數量
- 2. Python 2.7計數字符串的數量
- 3. 計數'x'字母的數字
- 4. 字符串中'x'字符的數量 - 遞歸
- 5. 字符串操作 - 獲取最後的'x'字符數量
- 6. 計算不同字符串的數量?
- 7. 計數字符串中的矢量
- 8. 使用'x'運算符計算數字乘積的函數?
- 9. PHP:計算字符串中的數學函數f(x)
- 10. 計數單個字母的數量在字符串中的R
- 11. 計數以字符'A'開始並以字符'X'結尾的子字符串
- 12. 計數字符
- 13. 字符計數
- 14. 計數字符
- 15. 字符計數
- 16. 計算數據中字母字符的數量
- 17. 計算字符串中最大數字的數量
- 18. 在int中計算字符數量
- 19. 計數字符在一個變量python
- 20. 對字符串X的出現進行計數的方法,採用可變數量的變量
- 21. 我如何計算字符串中特定字符的數量?
- 22. 在java中計算字符串中字符的確切數量
- 23. Spotfire:計算字符串中某個字符的數量
- 24. 計算字符串內特定字符的數量
- 25. 計算字符串中字符串的數量?
- 26. Scala - 計算字符串中相鄰重複字符的數量
- 27. 如何統計字符串內子字符串的數量
- 28. 如何計算Python字符串中每個字符的數量?
- 29. PowerShell的 - 計數的東西X的字符串
- 30. 計數數字簽名的數量?
你想** ** str_word_count http://us3.php.net/manual/en/function.str-word-count.php – Jakub 2010-12-15 21:24:02