[an error occurred while processing this directive] [an error occurred while processing this directive]

PHP – Les chaines de caractères

Extraire une chaine de caractères

Voici comment extraire une chaine de caractères d’une autre chaine.


function get_string_between($string, $start, $end){
    $string = " ".$string;
     $ini = strpos($string,$start);
     if ($ini == 0) return "";
     $ini += strlen($start);    
     $len = strpos($string,$end,$ini) - $ini;
     return substr($string,$ini,$len);
}
$string = "this [custom] function is useless!!";
echo get_string_between($string,"[","]");
// retourne "custom"

Publier par Michel PIALLIER dans PHP - Les chaines de caractères Commentaires fermés sur PHP – Extraire une chaine de caractères
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]