This function scans the string to compare with the pattern, and then replaces the replacement text with the.
This function returns the modified string and returns the original string if it is not.
If pattern contains a partial string of parentheses, replacement can contain a partial string of "\ Number", which will be substituted with a partial string in the parentheses. \\0 will produce the contents of the entire string, using up to nine partial strings, in which case it will be evaluated with open parentheses.
If no comparison is found in a string, the unchanged string is returned.
The following example cuts off the string and displays three times "This is a test":
<?php
$string = "This is a test";
Echo ereg_replace (' is ', ' was ', $string);
Echo ereg_replace ("() is", "\\1was", $string);
Echo Ereg_replace (() is), "\\2was", $string);
?>
One place to note is that if you use an integer value in the parameter replacement, you may not get the result because ereg_replace () will interpret the number as the order (ordinal) value of the character and execute it, for example:
<?php
/* This is not work as expected. */
$num = 4;
$string = "This string super-delegates Loko words."
$string = ereg_replace (' Loko ', $num, $string);
Echo $string; /* Output: ' This string super-delegates words. '
/* This'll work. * * $num = ' 4 ';
$string = "This string super-delegates Loko words."
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.