Return to Snippet

Revision: 46867
at May 27, 2011 00:28 by kyabas


Initial Code
function str_replace_once($needle , $replace , $haystack){ 
    // Looks for the first occurence of $needle in $haystack 
    // and replaces it with $replace. 
    $pos = strpos($haystack, $needle); 
    if ($pos === false) { 
        // Nothing found 
    return $haystack; 
    } 
    return substr_replace($haystack, $replace, $pos, strlen($needle)); 
}

Initial URL


Initial Description


Initial Title
str_replace_once

Initial Tags
replace

Initial Language
PHP