php Regex常用例子(1/9)

來源:互聯網
上載者:User

<?
  1  函數ereg的使用樣本。
  2  函數eregi()的用法樣本。
  3  替換匹配的字串。
  4  用eregi_repalce()替換匹配字串。
  5  使用函數split()。
  6  函數split()的使用。
  7  函數sql_regcase()產生Regex。
  8  Regex函數preg_grep()的用法樣本。
  9  用函數preg_match()進行Regex匹配。
  10 匹配函數preg_match_all()的應用。
  11 運算式搜尋和替換的函數preg_repalce()。
  12 通過Regex匹配的串分割字串。
  13 檢查ip地址的Regex樣本1。
  14 檢查ip地址的Regex樣本2。
  15 匹配中文字串。
  16 emailRegex。
  17 urlRegex。

*/

 // 1、函數ereg的使用樣本。
 

 代碼如下 複製代碼

$arr_date = array(
'2004-06-01',
'2005-0x-10',
'12-12-12',
'2000-12-25 00:10:20',
'2007-12-05'
);

for ($i=0; $i<5; ++$i)
{
 $date = $arr_date[$i];
 if(ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs))
 {
     echo "日期文字$date 符合'yyyy-mm-dd'格式:";
     echo "$regs[1].$regs[2].$regs[3]<br/><br/>";
 }
 else
 {
     echo "<b>日期文字$date 不符合'yyyy-mm-dd'格式的日期文字</b><br/><br/>";
 }
}

 

首頁 1 2 3 4 5 6 7 8 9 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.