StringTool

Cette classe contient un ensemble de méthodes statiques permettant de manipuler des chaînes de caractères.

Méthodes principales

start_with($string, $needle, $case_sensitive = true)

Vérifie si une chaîne de caractères commence par une autre.
StringTool :: start_with('nicolas', 'nic');        // true
StringTool :: start_with('nicolas', 'Nic');        // false
StringTool :: start_with('nicolas', 'Nic', false); // true

end_with($string, $needle, $case_sensitive = true)

Vérifie si une chaîne de caractères se termine par une autre.
StringTool :: end_with('nicolas', 'las');        // true
StringTool :: end_with('nicolas', 'Las');        // false
StringTool :: end_with('nicolas', 'Las', false); // true

get_value_between_chars($haystack, $index = 0, $opening_char = '[', $closing_char = ']')

Retourne une chaîne de caractères comprise entre deux caractères (ou chaînes de caractères) donnés.
Il est possible de retourner la nème occurence au lieu de la première par défaut.
StringTool :: get_value_between_chars('blabla[one]abcdefg[two]helloworld');    // 'one'
StringTool :: get_value_between_chars('blabla[one]abcdefg[two]helloworld', 1); // 'two'
StringTool :: get_value_between_chars('blabla[one]abcdefg[two]helloworld', 2); //  null

get_alphanumeric_random_string($length = 10)

Retourne une chaîne alpha-numérique aléatoire de la taille indiquée
StringTool :: get_alphanumeric_random_string();   //xXb2JXwAEg
StringTool :: get_alphanumeric_random_string(20); //ESskDOFdK67l60Tu6M6l

ensure_start_with($string, $leading_string)

S'assure qu'une chaîne de caractères commence par une autre chaîne de caractères
StringTool :: ensure_start_with('www.alaxos.net', 'http://');         // 'http://www.alaxos.net'
StringTool :: ensure_start_with('http://www.alaxos.net', 'http://')   // 'http://www.alaxos.net'

ensure_end_with($string, $trailing_string)

S'assure qu'une chaîne de caractères se termine par une autre chaîne de caractères
StringTool :: ensure_end_with('/path/to/my/folder', '/');   // '/path/to/my/folder/'
StringTool :: ensure_end_with('/path/to/my/folder/', '/');  // '/path/to/my/folder/'

remove_trailing($string, $trailing_string)

S'assure qu'une chaîne de caractères ne se termine pas par une autre chaîne de caractères
StringTool :: remove_trailing('/path/to/my/folder', '/');   // '/path/to/my/folder'
StringTool :: remove_trailing('/path/to/my/folder/', '/');  // '/path/to/my/folder'

is_valid_email($email)

S'assure que la chaîne de caractères donnée est une adresse email valide
StringTool :: is_valid_email('my_name@alaxos.net');   //true
StringTool :: is_valid_email('my_name@alaxos.n');     //false

shorten($string, $max_length = 100, $ellipse = '…', $clever_cut = true)

Retourne une une chaîne de caractères racourcie.
$ellipse
spécifie les caractères affichés à l'endroit de la coupure
$clever_cut
true → s'assure que la coupure ne se fait pas au milieu d'un mot
StringTool :: shorten('Lorem ipsum dolor sit amet', 12);                // 'Lorem...'
StringTool :: shorten('Lorem ipsum dolor sit amet', 12, '...', false);  // 'Lorem ips...'