PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mb_ereg_search_getpos> <mb_ereg_match
Last updated: Fri, 10 Oct 2008

view this page in

mb_ereg_replace

(PHP 4 >= 4.2.0, PHP 5)

mb_ereg_replaceRemplace des segments de chaînes, avec le support des expressions rationnelles multi-octets

Description

string mb_ereg_replace ( string $pattern , string $replacement , string $string [, string $option ] )

Analyse la chaîne string pour trouver des segments de chaînes correspondant au masque pattern , puis, elle les remplace avec le texte de remplacement replacement .

Liste de paramètres

pattern

L'expression rationnelle.

Les caractères multi-octets peuvent être utilisés dans pattern .

replacement

Le texte de remplacement.

string

La chaîne à analyser.

option
Des options de recherches peuvent être configurées avec le paramètre option . Si i est spécifié, la casse sera ignorée. Si x est spécifié, les espaces blancs seront ignorés. Si m est spécifié, la recherche se fera en mode multi-ligne, et les nouvelles lignes seront incluses dans le joker .. Si p est spécifié, la recherche se fera en mode POSIX, les nouvelles lignes seront considérées comme des caractères normaux. Si e est spécifiée, replacement sera évaluée comme une expression PHP.

Valeurs de retour

La chaîne résultante en cas de succès, ou FALSE si une erreur survient.

Notes

Note: L'encodage interne ou l'encodage des caractères spécifié par la fonction mb_regex_encoding() sera utilisé comme encodage de caractères pour cette fonction.



mb_ereg_search_getpos> <mb_ereg_match
Last updated: Fri, 10 Oct 2008
 
add a note add a note User Contributed Notes
mb_ereg_replace
keizo at gomo dot jp
23-Jul-2008 09:32
<?php
$pattern
= "([あ-ん]+)[0-9]+";
$string = mb_ereg_replace($pattern, '「\\1」:\\0', $string);
?>

you can use \\n for capture group in replacement
gmx dot net at ulrich dot mierendorff
01-Jul-2008 07:39
If you want to replace characters like "ä" or "ø" you can use mb_ereg_replace, but it is very slow. str_replace is much faster and also works with characters like "ä" or "ø"!

I think this has something to with the fact that str_replace works on byte level and does not care about characters.
I hope that can help.
04-Dec-2006 08:36
'i' option does not work correctly with multibyte characters. The function does not locate/replace the multibyte string if it's different case then specified on multibyte needle which is in different case.
squeegee
01-Nov-2006 07:41
well, if you just calculated the length of the find and replace strings once instead of on every loop, it would likely speed it up a lot.
mpnicholas [@t] gmail (dot) com
09-Jul-2006 03:09
Regarding the mb_str_ireplace() function: I benchmarked it against mb_eregi_replace() for single-character substitution, and it was significantly slower. Despite avoiding the ereg call, I think the while loop ends slowing you down too much for this to be practical.
vondrej(at)gmail(dot)com
26-Feb-2006 03:47
Are you looking for htmlentities() for multibyte strings? This might help you - it just replace <, >, ", '

/**
 *  Multibyte equivalent for htmlentities() [lite version :)]
 *
 * @param string $str
 * @param string $encoding
 * @return string
 **/
function mb_htmlentities($str, $encoding = 'utf-8') {
    mb_regex_encoding($encoding);
    $pattern = array('<', '>', '"', '\'');
    $replacement = array('&lt;', '&gt;', '&quot;', '&#39;');
    for ($i=0; $i<sizeof($pattern); $i++) {
        $str = mb_ereg_replace($pattern[$i], $replacement[$i], $str);
    }
    return $str;
}
faxe at neostrada dot pl
09-Aug-2005 03:52
A simple mb_str_ireplace() implementation - a faster (?) replacement for non-regexp multi-byte string replacement:

[code]
function mb_str_ireplace($co, $naCo, $wCzym)
{
    $wCzymM = mb_strtolower($wCzym);
    $coM    = mb_strtolower($co);
    $offset = 0;
   
    while(($poz = mb_strpos($wCzymM, $coM, $offset)) !== false)
    {
        $offset = $poz + mb_strlen($naCo);
        $wCzym = mb_substr($wCzym, 0, $poz). $naCo .mb_substr($wCzym, $poz+mb_strlen($co));
        $wCzymM = mb_strtolower($wCzym);
    }
   
    return $wCzym;
}[/code]

mb_ereg_search_getpos> <mb_ereg_match
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites