replace-string-easy.php

<?php

function replacestring($search,$replace,$subject) {
    $srchlen=strlen($search);    // lenght of searched string
    if ($srchlen==0) return $subject;
    $find = $subject;
    while ($find = stristr($find,$search)) {    // find $search text in $subject - case insensitiv
        $srchtxt = substr($find,0,$srchlen);    // get new search text
        $find=substr($find,$srchlen);
        $subject = str_replace($srchtxt,$replace,$subject);    // replace founded case insensitive search text with $replace
    }
    return $subject;
}

$a="Hello world, hello world, hello World, HelLo WOrld";

echo replacestring("hello","<b>hello</b>",$a);

?> 
 
info/replace-string-easy.txt · Dernière modification: 2008/11/11 11:37 (modification externe)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki