mb_ereg_replace

(PHP 4 >= 4.2.0)

mb_ereg_replace -- Replace regular expression with multibyte support

Description

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

mb_ereg_replace() scans string for matches to pattern, then replaces the matched text with replacement and returns the result string or FALSE on error. Multibyte character can be used in pattern.

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.

The internal encoding or the character encoding specified in mb_regex_encoding() will be used as character encoding.

See also: mb_regex_encoding(), mb_eregi_replace().



mb_ereg_replace
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_matchmb_ereg_search_getpos>
 Last updated: Tue, 15 Nov 2005