This is bssn's weblog, which is about Bssn's Internet Life, IT information, webmaters and etc.

My php Notes 4: The regular expression

The regular expression directly to the feeling that things-liang, a really good / cy

Basic syntax: int ereg (string pattern, string string [, array & regs])

Common: ereg, ereg_replace, eregi_replace, eregi, split, spliti

php manual notes that the use of Perl regular expression syntax is compatible with the preg_match () function normally than ereg () faster alternative to study it before

Replacement at links:

<? php
$ text = ereg_replace ("[[: alpha :]] ://[^<>[: space :]] [[: alnum :]/]",
"<a href=\"\\0\"> \ \ 0 </ a>", $ text);
«>

/ * If the pattern includes a sub-string in brackets, the replacement can contain the form \ \ digit sub-string, these strings of numbers will be replaced by that of several of the brackets within the sub-string; \ \ 0 contain The entire contents of the string. Up to nine sub-strings can be used. Brackets can be nested, the circumstances in order to calculate the left parentheses * /

Even the practice through the regular replacement of judge-mail address:

function check_mail ($ mail) (
ereg ( "([a-zA-Z0-9 ]. )(@[ a-zA-Z0-9 ]. )( \. [a-zA-Z ] $)",$ mail, $ mails );
if (strlen ($ mails [1])> 0 & & strlen ($ mails [2])> 0 & & strlen ($ mails [3])> 0) (
$ newmail = ereg_replace ($ mails [2], "@ yahoo", $ mail);
echo $ newmail;
)
else
echo "e-mail address wrong, you Huyou I";
)

echo check_mail ( "asdfsd@sdfsd.com"). "
";
echo check_mail ( "sdfasdf.com
")."
";
echo check_mail ( "asdfsd.comsdfas @ asdf.com"). "
";
«>

Related Log

Only one of the "four of my php Notes: The regular expression" made a comment


  1. Heartshare »Blog Archive» PHP learning some of the collection sites and resources Reply to this comment said:

    [...] Http://san-tin.com/blog/2006/12/31/161903/ http://www.zhaomingliang.com/category/php/ good uh http://www.bssn. org / bssn-php-erge.html http://www.elaguan.net/show-290-1.html http://www.webxuexi.net/catalog.asp?cate=7 [...]

Leave a Reply