Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

mb_ereg_replace

Description

The mb_ereg_replace of Multibyte String for PHP replace regular expression with multibyte support.

Syntax

mb_ereg_replace(
    string $pattern,
    string $replacement,
    string $string,
    ?string $options = null
): string|false|null

Parameters

pattern

The regular expression pattern.

Multibyte characters may be used in pattern.

replacement

The replacement text.

string

The string being checked.

options

The search option.

OptionDescription
iAmbiguity match on
xEnables extended pattern form
m'.' matches with newlines
s'^' -> '\A', '$' -> '\Z'
pSame as both the m and s options
lFinds longest matches
nIgnores empty matches

Return

The resultant string on success, or false on error. If string is not valid for the current encoding, null is returned.

Examples

1 · pattern replacement string

<?

$pattern = '🐘(st(r(i)ng))';
$replacement = 'replacement';
$string = '🐘string';

$return = mb_ereg_replace($pattern, $replacement, $string);

var_export($return);
'replacement'

2 · options · i

<?

$pattern = '🐘STRING';
$replacement = 'replacement';
$string = '🐘string';
$options = 'i';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'replacement'

3 · options · x

<?

$pattern = '🐘 s t r i n g';
$replacement = 'replacement';
$string = '🐘string';
$options = 'x';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'replacement'

4 · options · m

<?

$pattern = '.🐘string';
$replacement = 'replacement';
$string = '
🐘string';
$options = 'm';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'replacement'

5 · options · s

<?

$pattern = '^🐘string$';
$replacement = 'replacement';
$string = '🐘string';
$options = 's';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'replacement'

6 · options · p

<?

$pattern = '^.🐘string$';
$replacement = 'replacement';
$string = '
🐘string';
$options = 'p';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'replacement'

7 · options · l

<?

$pattern = '🐘.*tring';
$replacement = 'replacement';
$string = '🐘stringtring';
$options = 'l';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'replacement'

8 · options · n

<?

$pattern = '';
$replacement = 'replacement';
$string = '🐘string';
$options = 'n';

$return = mb_ereg_replace($pattern, $replacement, $string, $options);

var_export($return);
'🐘string'
HomeMenu