<?php
$pattern = "([あ-ん]+)[0-9]+";
$string = mb_ereg_replace($pattern, '「\\1」:\\0', $string);
?>
you can use \\n for capture group in replacement
mb_ereg_replace
(PHP 4 >= 4.2.0, PHP 5)
mb_ereg_replace — Replace regular expression with multibyte support
Descrizione
string mb_ereg_replace
( string $pattern
, string $replacement
, string $string
[, string $option
] )
Scans string for matches to pattern , then replaces the matched text with replacement
Elenco dei parametri
- pattern
-
The regular expression pattern.
Multibyte characters may be used in pattern .
- replacement
-
The replacement text.
- string
-
The string being checked.
- option
- Matching condition can be set by option parameter. If i is specified for this parameter, the case will be ignored. If x is specified, white space will be ignored. If m is specified, match will be executed in multiline mode and line break will be included in '.'. If p is specified, match will be executed in POSIX mode, line break will be considered as normal character. If e is specified, replacement string will be evaluated as PHP expression.
Valori restituiti
The resultant string on success, or FALSE on error.
Note
Nota: La codifica interna o la codifica dei caratteri specificata da mb_regex_encoding() sarà utilizzata come codifica ei caratteri per questa funzione.
mb_ereg_replace
keizo at gomo dot jp
23-Jul-2008 09:32
23-Jul-2008 09:32
gmx dot net at ulrich dot mierendorff
01-Jul-2008 07:39
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
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
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
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('<', '>', '"', ''');
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
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]
