"Lars B. Jensen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> depending on what you're replacing with what, a solution is eregi_replace.
I
> do not advice to upper nor lowercase the source as it will change parts of
> data unwantedly.

Yes, I agree; another solution is as follows:

function alt_str_replace($search, $replace, $subject) {

    // Temporary copies of search string and subject string;
    //  both shifted to lowercase to make the search case insensitive.
    $t_search = strtolower($search);
    $t_subject = strtolower($subject);

    // Initialize result string
    $res = "";

    // Initialize search vars
    $search_offs = 0;
    $shift = strlen($search);

    // As long as another match is found...
    while (($t = strpos($t_subject, $t_search, $search_offs)) !== false) {
        // Copy non-matching portion of string
        $res .= substr($subject, $search_offs, $t-$search_offs);
        // Add replacement value
        $res .= $replace;

        // Update search offset
        $search_offs = $t + $shift;
    }

    // Add trailing end of string
    $res .= substr($subject, $search_offs);

    return $res;
}

Hope that helps...



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to