PHP Class JpnForPhp\Helper\Helper

Author: Matthieu Bilbille (@mbilbille)
Afficher le fichier Open project: mbilbille/jpnforphp Class Usage Examples

Méthodes publiques

Méthode Description
charAt ( string $str, integer $index ) : string Returns the character at the specified index.
convertHiraganaToKatakana ( string $str ) : string Convert the given string from hiragana to katakana.
convertKatakanaToHiragana ( string $str ) : string Convert the given string from katakana to hiragana.
countSubString ( string $str, string $needle ) : integer Counts the number of substring occurrences.
extractHiragana ( string $str, integer $length, boolean $yoon = false ) : array Split a given string to extract hiragana substrings.
extractKana ( string $str, integer $length, boolean $yoon = false ) : array Split a given string to extract kana substrings.
extractKanji ( string $str, integer $length ) : array Split a given string to extract kanji substrings.
extractKatakana ( string $str, integer $length, boolean $yoon = false ) : array Split a given string to extract katakana substrings.
removeMacrons ( string $str ) : string Remove macrons from the specified string.
split ( string $str, integer $length = 1, boolean $yoon = false ) : array Enhance default splitter function to handle UTF-8 characters.
subString ( string $str, integer $begin, integer $length ) : string Returns a new string that is a substring of the given string.
trim ( string $str ) : string Enhance default trim() to trim unicode whitespace.

Method Details

charAt() public static méthode

Returns the character at the specified index.
See also: subString()
public static charAt ( string $str, integer $index ) : string
$str string The input string.
$index integer The index of the character to return (0 based indexing).
Résultat string The character at the specified index.

convertHiraganaToKatakana() public static méthode

Simply wrap the mb_convert_kana function.
public static convertHiraganaToKatakana ( string $str ) : string
$str string String to be converted.
Résultat string Converted string.

convertKatakanaToHiragana() public static méthode

Simply wrap the mb_convert_kana function.
public static convertKatakanaToHiragana ( string $str ) : string
$str string String to be converted.
Résultat string Converted string.

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.

extractHiragana() public static méthode

Split a given string to extract hiragana substrings.
public static extractHiragana ( string $str, integer $length, boolean $yoon = false ) : array
$str string The input string.
$length integer (optional) Define an optional substring length. Default to 0 which means substrings will be returned as it is.
$yoon boolean (optional) Whether considering the base syllable and the following yoon character as a single character or not Default to false.
Résultat array An array of hiragana substrings.

extractKana() public static méthode

Split a given string to extract kana substrings.
public static extractKana ( string $str, integer $length, boolean $yoon = false ) : array
$str string The input string.
$length integer (optional) Define an optional substring length. Default to 0 which means substrings will be returned as it is.
$yoon boolean (optional) Whether considering the base syllable and the following yoon character as a single character or not Default to false.
Résultat array An array of kana substrings.

extractKanji() public static méthode

Split a given string to extract kanji substrings.
public static extractKanji ( string $str, integer $length ) : array
$str string The input string.
$length integer (optional) Define an optional substring length. Default to 0 which means substrings will be returned as it is.
Résultat array An array of kanji substrings.

extractKatakana() public static méthode

Split a given string to extract katakana substrings.
public static extractKatakana ( string $str, integer $length, boolean $yoon = false ) : array
$str string The input string.
$length integer (optional) Define an optional substring length. Default to 0 which means substrings will be returned as it is.
$yoon boolean (optional) Whether considering the base syllable and the following yoon character as a single character or not Default to false.
Résultat array An array of katakana substrings.

removeMacrons() public static méthode

Based on Wordpress remove_accents().
public static removeMacrons ( string $str ) : string
$str string The input string.
Résultat string Cleaned string.

split() public static méthode

Enhance default splitter function to handle UTF-8 characters.
public static split ( string $str, integer $length = 1, boolean $yoon = false ) : array
$str string The string to split.
$length integer (optional) Define an optional substring length. Default to 1.
$yoon boolean (optional) Whether considering the base syllable and the following yoon character as a single character or not Default to false.
Résultat array An array of strings.

subString() public static méthode

Returns a new string that is a substring of the given string.
See also: mb_substr()
public static subString ( string $str, integer $begin, integer $length ) : string
$str string The input string.
$begin integer The beginning index, inclusive.
$length integer Maximum number of characters to use from str.
Résultat string A substring

trim() public static méthode

Enhance default trim() to trim unicode whitespace.
public static trim ( string $str ) : string
$str string The input string.
Résultat string A cleaned string.