Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
tips_informatiques:programmation:php:plugin_alaxos:librairie:stringtool [2010/08/24 21:48] nico créée |
tips_informatiques:programmation:php:plugin_alaxos:librairie:stringtool [2010/08/24 00:00] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== StringTool ====== | ====== 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. | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: start_with('nicolas', 'nic'); // true | ||
+ | StringTool :: start_with('nicolas', 'Nic'); // false | ||
+ | StringTool :: start_with('nicolas', 'Nic', false); // true | ||
+ | </code> | ||
+ | |||
+ | **end_with($string, $needle, $case_sensitive = true)** | ||
+ | |||
+ | >Vérifie si une chaîne de caractères se termine par une autre. | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: end_with('nicolas', 'las'); // true | ||
+ | StringTool :: end_with('nicolas', 'Las'); // false | ||
+ | StringTool :: end_with('nicolas', 'Las', false); // true | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **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<sup>ème</sup> occurence au lieu de la première par défaut. | ||
+ | |||
+ | |||
+ | <code php> | ||
+ | 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 | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **get_alphanumeric_random_string($length = 10)** | ||
+ | |||
+ | >Retourne une chaîne alpha-numérique aléatoire de la taille indiquée | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: get_alphanumeric_random_string(); //xXb2JXwAEg | ||
+ | StringTool :: get_alphanumeric_random_string(20); //ESskDOFdK67l60Tu6M6l | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **ensure_start_with($string, $leading_string)** | ||
+ | |||
+ | >S'assure qu'une chaîne de caractères commence par une autre chaîne de caractères | ||
+ | |||
+ | <code php> | ||
+ | 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' | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **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 | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: ensure_end_with('/path/to/my/folder', '/'); // '/path/to/my/folder/' | ||
+ | StringTool :: ensure_end_with('/path/to/my/folder/', '/'); // '/path/to/my/folder/' | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **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 | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: remove_trailing('/path/to/my/folder', '/'); // '/path/to/my/folder' | ||
+ | StringTool :: remove_trailing('/path/to/my/folder/', '/'); // '/path/to/my/folder' | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **is_valid_email($email)** | ||
+ | |||
+ | >S'assure que la chaîne de caractères donnée est une adresse email valide | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: is_valid_email('my_name@alaxos.net'); //true | ||
+ | StringTool :: is_valid_email('my_name@alaxos.n'); //false | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | **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 | ||
+ | |||
+ | <code php> | ||
+ | StringTool :: shorten('Lorem ipsum dolor sit amet', 12); // 'Lorem...' | ||
+ | StringTool :: shorten('Lorem ipsum dolor sit amet', 12, '...', false); // 'Lorem ips...' | ||
+ | </code> | ||
+ | |||