countSubString() public static méthode

Counts the number of substring occurrences.
See also: mb_substr_count()
public static countSubString ( string $str, string $needle ) : integer
$str string The input string.
$needle string The string being found.
Résultat integer The number of times the needle substring occurs in the input string.
Exemple #1
0
 /**
  * Override transliterate().
  *
  * @see TransliterationSystem
  */
 public function transliterate($str, $stripwhitespace = self::STRIP_WHITESPACE_NONE)
 {
     $str = parent::transliterate($str);
     // Strip whitespace(s) here
     switch ($stripwhitespace) {
         case self::STRIP_WHITESPACE_AUTO:
             if (Helper::countSubString($str, ' ') > self::STRIP_WHITESPACE_AUTO_NB_SPACES) {
                 break;
             }
         case self::STRIP_WHITESPACE_ALL:
             $str = preg_replace('/\\s/u', '', $str);
             break;
     }
     return $str;
 }
Exemple #2
0
 public function testCountSubStringWhenNoOccurencesFound()
 {
     $result = Helper::countSubString($this->mixCharacters, '漢');
     $this->assertEquals(0, $result);
 }