Its prototype follows:
int eregi(string pattern, string string, [array regs])
CHAPTER 9 ?– S TRINGS AND REGULAR EXPRESS IONS 237
This function can be useful when checking the validity of strings, such as passwords.
This concept is illustrated in the following example:
$pswd = "jasonasdf";
if (!eregi("^[a-zA-Z0-9]{8,10}$", $pswd))
echo "Invalid password!";
else
echo "Valid password!";
?>
In this example, the user must provide an alphanumeric password consisting of
eight to ten characters, or else an error message is displayed.
Replacing Text in a Case-Sensitive Fashion
The ereg_replace() function operates much like ereg(), except that its power is
extended to finding and replacing a pattern with a replacement string instead of
simply locating it. Its prototype follows:
string ereg_replace(string pattern, string replacement, string string)
If no matches are found, the string will remain unchanged. Like ereg(),
ereg_replace() is case sensitive. Consider an example:
$text = "This is a link to http://www.wjgilmore.com/.";
echo ereg_replace("http://([a-zA-Z0-9./-]+)$",
"
\\0",
$text);
?>
This returns the following:
This is a link to
http://www.wjgilmore.com.
A rather interesting feature of PHP??™s string-replacement capability is the ability to
back-reference parenthesized substrings.
Pages:
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315