55 inscrits



  • Visites de la page : [169]
  • Catégorie : Chaînes
  • Modifié le : 04-07-2005
  • Site auteur : Site de l'auteur




Fonction permettant de remplacer seulement la première occurrence d'une chaîne donnée (contrairement à la fonction str_replace)


   Code:
<?php 

function str_replace_once($from$to$str) { 
    if(!
$newStr strstr($str$from)) { 
        return 
$str
    } 
    
$iNewStrLength strlen($newStr); 
    
$iFirstPartlength strlen($str) - $iNewStrLength
    return 
substr($str0$iFirstPartlength).$to.substr($newStrstrlen($from), $iNewStrLength); 


$s 'Joe is here but jack is not here.'
echo 
str_replace_once('here''xxx'$s); 
// will display 
// Joe is xxx but jack is not here. 
?>


Aucun commentaire pour l'instant !



Nom / Pseudo :    
Email :
image de securisation du formulaire
Commentaire :




.: Easy-Script © 2002/2008 - Tous droits réservés - CNIL N°1098778 - Gén en 0.652 sec :.                        Top