background preloader

Php variable caractere

Facebook Twitter

Strpos. This is a bit more useful when scanning a large string for all occurances between 'tags'.

strpos

<? Phpfunction getStrsBetween($s,$s1,$s2=false,$offset=0) { getStrsBetween(string, tag1, <tag2>, <offset> If no second tag is specified, then match between identical tags Returns an array indexed with the encapsulated text, which is in turn a sub-array, containing the position of each item. Strstr. If you want to use the $before_needle parameter that's only in PHP 5.3.0, I found a way to use it in lower versions.

strstr

The code is a bit hefty, but it works. It also has added $include_needle and $case_sensitive. if(! Isset($before_needle)){ $before_needle=false; } if(! If(! If(! // Example $email = 'user@example.com'; $domain = strstrbi($email, '@', false, false, false); echo $domain; Htmlentities. Nettoyer une chaîne de caractères. L’URL Rewriting est beaucoup utilisé de nos jours et cette méthode requiert de savoir nettoyer une chaîne de caractères, c’est-à-dire transformer par exemple « Chaîne à nettoyer » en « chaine-a-nettoyer ».

Nettoyer une chaîne de caractères

Nettoyer une chaîne ? Nettoyer une chaîne, cela signifie simplement remplacer ses caractères accentués, ses espaces, etc. par d’autres caractères. Par exemple on pourra envoyer « Nettoyer une chaîne de caractères » à notre fonction et elle nous renverra « nettoyer-une-chaine-de-caracteres ». Cela s’utilise principalement pour l’URL Rewriting afin d’obtenir une adresse du style « titre-de-l-article.html » au lieu de « article.php? Id=42 ». Comment ? Maintenant qu’on a vu ce qu’on voulait faire, passons à l’action. Nous n’avons besoin que d’un seul argument : la chaîne à transformer. Nous allons utiliser une fonction PHP qui fera en une seule ligne toutes les transformations qu’on lui aura demandé.

Ce n’est bien sûr pas fini, mais presque. Il ne nous reste plus grand-chose maintenant. Validation.