JpnForPhp\Helper\Helper::countSubString PHP Method

countSubString() public static method

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.
return integer The number of times the needle substring occurs in the input string.
    public static function countSubString($str, $needle)
    {
        return mb_substr_count($str, $needle, 'UTF-8');
    }

Usage Example

Beispiel #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;
 }
All Usage Examples Of JpnForPhp\Helper\Helper::countSubString