PHP Regular Expression ereg() function ereg(“([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})”, $date, $regs); $string = “MMMMMM”; ereg(“(.{2}) (.{2}) (.{2})”, $stirng, $nums); $nums[0] = “MMMMMM”; $nums[1]=”MM”; $nums[2]=”MM”; $nums[3]=”MM”; Ereg_replace() function string ereg_replace(string pattern, string replacement, string string); Example $sting = “This is a test.”; Echo ereg_replace(“ is”,” was”, $string).”
”; Echo ereg_replace(“( ) is”, “\\1was”, $string).”
”; Echo ereg_replace(“(( ) is)”, “\\2was”, $string). “
”; $html = ‘
Return to Home Page
’; Echo ereg_replace(“<([^>]|\n)*>”, “”, $html); ?> Eregi() function Int eregi(string pattern, string string, array [regs]); Eregi() function same as ereg() function, but not have A and a problem Eregi_replace() function String eregi_replace(string pattern, string replacement, string string); Eregi_replace function same as ereg_replace() function, but not have A and a problem.
Split() function Array split(string pattern, string string, int [limit]); $passwd_list = `cat /etc/passwd`; $passwd_list = split( “:”, $passwd_list); For($i =0; $i<(count($passwd_list)+1)/7;$i++) { Echo “
\n”; For($j =0; $j<7; $j++) Echo $passwd_list[$i*7+$j];.” “; } ?> Sql_regcase() function String sql_regcase(string string); Echo sql_recase(“Jollen”); [Jj][Oo][Ll][Ll][Ee][Nn] $query = “select * from student where fullname = ‘“.sql_regcase(‘chen Jin-Hong’).“ ’ ”; echo $qery; Output: select * from student where fullname = ‘ [Cc][Hh][Ee][Nn][Jj][Ii][Nn][Hh][Oo][Nn] [Gg] ‘ Pattern purpose e* 符合零個以上 e+ 符合一個或以上 e? 符合一個或零個 {n} 用途和 mysql 的語法一樣 {n,} . . {n, m} . . ^ . . $ . . . 任何字元,但不包含’\n’ | 用途和 mysql 的語法一樣 […] 用途和 mysql 的語法一樣. Php 也有類別用法, 因 此”…”也可以是類別常數, 在後面提到
Example ab*c ac abbc abbbbbbbbc ab+c abbc abbbc abbbbbbbbbbc ab?c abc ac 類別符合類別的字元 Alpha 0-9 ||a-z A-Z Blank Space || Tab Cntrl ASCII 0 ~ ASCII 32 的控制字元 Lower 所有小寫字母 Upper 所有大寫字母 Space Space tab newline linefeed || formfeed characters Xdigit 合法的十六進位數字