PHP – mb_eregi_replace() function

PHPServer Side ProgrammingProgramming

In PHP, mb_eregi_replace() is used to replace a regular expression with a multibyte support, ignoring case. This function will scan the string for matches to the pattern, then it will replace the matched text with the replacement. This function is supported in PHP 4.2 or higher version.

Syntax

string mb_eregi_replace(str $pattern, str $replacement, str $string, str $options)

Parameters

mb_eregi_replace() accepts the following four parameters −

  • $pattern − This parameter is used for the regular expression pattern and it may be used multibyte characters. The case will be ignored.

  • $replacement − This parameter is used for text replacement.

  • $string − The string parameter is used to search the string.

  • $options − It is used for the search option.

Return Values

mb_eregi_replace() will return the resultant string on success or it will return an error. It will return an error if the string is not valid for the current encoding.

Example

<?php
   //encoding = "UTF-8"
   $re=mb_regex_encoding("UTF-8");

   //The mb_eregi_replace function will replace
   //the 'p' to 'P' characters
   $string=mb_eregi_replace("[p]","P","pHp Tutorial");

   var_dump($re);
   var_dump($string);
?>

Output

bool(true)
string(12) "PHP Tutorial"
raja
Published on 11-Oct-2021 13:02:17
Advertisements