2010-12-15 2 views
1

Ich experimentiere mit etwas, bei dem explode() fehlschlägt, also möchte ich etwas anderes versuchen. Wenn ich einen String, wie kann ich die Anzahl der Zeichen in sie zählen, die vermietet werden wir an, ein comma wie in ,Zählnummer des X-Zeichens

+0

Sie wollen ** ** str_word_count http://us3.php.net/manual/en/function.str-word-count.php – Jakub

Antwort

1

können Sie count_chars

Beispiel von PHP Manual verwenden:

$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"; 
} 

Ausgang (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

Vergessen Sie nicht, 'isset ($ result [‘ zu überprüfen, ']) 'wenn es keine Garantie gibt, dass ein Komma in der Zeichenfolge ist (Möglichkeit für kein Komma-Element im Ergebnis-Array) –

Verwandte Themen