The following functions create new strings by replacing substrings:
string ereg_replace(string pattern, string replacement, string source)
string eregi_replace(string pattern, string replacement, string source)
They create a new string by replacing substrings of the source string that match the regular expression pattern with a replacement string. These functions are similar to the str_replace( ) function described earlier in the Section 2.6 section, except that the replaced substrings are identified using a regular expression. Consider the examples:
$source = "The quick\tbrown\n\tfox jumps";
// prints "The quick brown fox"
echo ereg_replace("[ \t\n]+", " ", $source);
$source = "\xf6 The quick\tbrown\n\tfox jumps\x88";
// replace all non-printable characters with a space
echo ereg_replace("[^ -~]+", " ", $source);
The second example uses the regular expression "[^ -~]+" to match all characters except those that fall between the space character and the tilde character in the ASCII table. This represents almost all the printable 7-bit characters.
string ereg_replace(string pattern, string replacement, string source)
string eregi_replace(string pattern, string replacement, string source)
They create a new string by replacing substrings of the source string that match the regular expression pattern with a replacement string. These functions are similar to the str_replace( ) function described earlier in the Section 2.6 section, except that the replaced substrings are identified using a regular expression. Consider the examples:
$source = "The quick\tbrown\n\tfox jumps";
// prints "The quick brown fox"
echo ereg_replace("[ \t\n]+", " ", $source);
$source = "\xf6 The quick\tbrown\n\tfox jumps\x88";
// replace all non-printable characters with a space
echo ereg_replace("[^ -~]+", " ", $source);
The second example uses the regular expression "[^ -~]+" to match all characters except those that fall between the space character and the tilde character in the ASCII table. This represents almost all the printable 7-bit characters.
0 comments:
Post a Comment