99色视频在线观看-99色视频在线-99色视频-99色精品-99色播-99色吧

 
深圳網站優化排名

將想法與焦點和您一起共享

深圳網站建設設計 深圳網站優化排名 深圳網站設計制作欣賞

網站制作開始使用PHP正則表達式

2017-07-28  閱讀: 深圳網站建設設計

網站制作開始使用PHP正則表達式

1。正則表達式是什么?
正則表達式的主要目的,也被稱為正則表達式或regexp,是有效地搜索模式在一個給定的文本。這些搜索模式是使用正則表達式解析器理解的特殊格式編寫的。

正則表達式是從UNIX系統,其中設計了一個程序,調用grep,幫助用戶處理字符串和文本操作。通過遵循幾個基本規則,可以創建非常復雜的搜索模式。

舉個例子,假設你被賦予了檢查電子郵件或電話號碼是否正確的任務。使用一些簡單的命令,由于正則表達式,這些問題可以很容易地得到解決。語法一開始并不總是那么簡單,但是一旦你學會了它,你就會意識到你可以很容易地完成相當復雜的搜索,只需輸入幾個字符,你就可以從不同的角度處理問題。

網站制作開始使用PHP正則表達式

2。兼容正則表達式庫

PHP實現了相當多的正則表達式功能,使用不同的分析引擎。有兩個主要的PHP解析器。一個叫POSIX和PCRE兼容正則表達式或其他。
POSIX的PHP函數的前綴是ereg_。自發布的PHP 5.3這臺發動機是過時的,但讓我們更優更快PCRE引擎一看。
在PHP PCRE函數一開始preg_如preg_match或preg_replace。您可以在PHP文檔中讀取完整的函數列表。


3.基本語法
要使用正則表達式首先需要學習語法。該語法由一系列字母、數字、點、連字符和特殊標志,我們可以一起使用不同的括號。
在PHP中,每個正則表達式模式都被定義為使用Perl格式的字符串。在Perl,一個正則表達式模式是寫在斜杠,如/你好/。在PHP中這將成為一個字符串,“你好”。

Now, let’s have a look at some operators, the basic building blocks of regular expressions
Operator     Description
^     The circumflex symbol marks the beginning of a pattern, although in some cases it can be omitted
$     Same as with the circumflex symbol, the dollar sign marks the end of a search pattern
.     The period matches any single character
?     It will match the preceding pattern zero or one times
+     It will match the preceding pattern one or more times
*     It will match the preceding pattern zero or more times
|     Boolean OR
–     Matches a range of elements
()     Groups a different pattern elements together
[]     Matches any single character between the square brackets
{min, max}     It is used to match exact character counts
d     Matches any single digit
D     Matches any single non digit caharcter
w     Matches any alpha numeric character including underscore (_)
W     Matches any non alpha numeric character excluding the underscore character
s     Matches whitespace character

As an addition in PHP the forward slash character is escaped using the simple slash . Example: ‘/he/llo/’

To have a brief understanding how these operators are used, let’s have a look at a few examples:
Example     Description
‘/hello/’     It will match the word hello
‘/^hello/’     It will match hello at the start of a string. Possible matches are hello or helloworld, but not worldhello
‘/hello$/’     It will match hello at the end of a string.
‘/he.o/’     It will match any character between he and o. Possible matches are helo or heyo, but not hello
‘/he?llo/’     It will match either llo or hello
‘/hello+/’     It will match hello on or more time. E.g. hello or hellohello
‘/he*llo/’     Matches llo, hello or hehello, but not hellooo
‘/hello|world/’     It will either match the word hello or world
‘/(A-Z)/’     Using it with the hyphen character, this pattern will match every uppercase character from A to Z. E.g. A, B, C…
‘/[abc]/’     It will match any single character a, b or c
‘/abc{1}/’     Matches precisely one c character after the characters ab. E.g. matches abc, but not abcc
‘/abc{1,}/’     Matches one or more c character after the characters ab. E.g. matches abc or abcc
‘/abc{2,4}/’     Matches between two and four c character after the characters ab. E.g. matches abcc, abccc or abcccc, but not abc

除了操作符之外,還有正則表達式修飾符,它可以全局改變搜索模式的行為。

正則表達式修飾符放在模式,這樣/你好/我和他們由單字母如我這標志著一個模式不區分大小寫或X忽略空白字符。要獲得修飾符的完整列表,請訪問PHP的在線文檔。

正則表達式的真正力量依賴于合并這些操作符和修飾符,因此創建相當復雜的搜索模式。

網站制作開始使用PHP正則表達式
4. Using Regex in PHP

In PHP we have a total of nine PCRE functions which we can use. Here’s the list:

    preg_filter – performs a regular expression search and replace
    preg_grep – returns array entries that match a pattern
    preg_last_error – returns the error code of the last PCRE regex execution
    preg_match – perform a regular expression match
    preg_match_all – perform a global regular expression match
    preg_quote – quote regular expression characters
    preg_replace – perform a regular expression search and replace
    preg_replace_callback – perform a regular expression search and replace using a callback
    preg_split – split string by a regular expression

The two most commonly used functions are preg_match and preg_replace.

Let’s begin by creating a test string on which we will perform our regular expression searches. The classical hello world should do it.

$test_string = 'hello world';

If we simply want to search for the word hello or world then the search pattern would look something like this:

preg_match('/hello/', $test_string);
preg_match('/world/', $test_string);


如果我們想看看字符串是否以hello開頭,我們只需在搜索模式的開頭放置這個字符:
preg_match('/^hello/', $test_string);

請注意,正則表達式是區分大小寫的,上面的模式將不匹配hello這個單詞。如果我們希望我們的模式不區分大小寫,我們應該應用下面的修飾符:

preg_match('/^hello/i', $test_string);    

請注意在斜杠后面的模式后面的字符i。

現在讓我們來研究一個更復雜的搜索模式。如果我們要檢查字符串中的前五個字符是alpha數字字符怎么辦?。

preg_match('/^[A-Za-z0-9]{5}/', $test_string);

讓我們來剖析這個搜索模式。首先,采用插入字符(^)我們指定的字符串必須以一個字母數字字符。這是由[就]指定。

從A到Z的字母A-Z,其次是相同的除了小寫字符的所有字符,這是很重要的,因為正則表達式是大小寫敏感。我想你會明白自己什么0-9的手段。

{ 5 }只是告訴正則表達式分析器的準確計數五字。如果我們將六替換為五,解析器將不匹配任何東西,因為在我們的測試字符串中,hello是五個字符長,后面是空格字符,在我們的例子中是不計數的。

此外,這個正則表達式可以優化為以下形式:

preg_match('/^w{5}/', $test_string);

w specifies any alpha numeric characters plus the underscore character (_).


6。有用的正則表達式函數

下面是一些使用正則表達式的PHP函數,您可以在日常中使用它們。

驗證電子郵件。這個函數將驗證給定的電子郵件地址字符串,以確定它是否有正確的格式。

function validate_email($email_address)
{
    if( !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+
                     ([a-zA-Z0-9._-]+)+$/", $email_address))
    {
        return false;
    }    
    return true;
}

Validate a URL

function validate_url($url)
{
    return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?
                      (/.*)?$|i', $url);
}

Remove repeated words. I often found repeated words in a text, such as this this. This handy function will remove such duplicate words.

function remove_duplicate_word($text)
{
    return preg_replace("/s(w+s)1/i", "$1", $text);
}

Validate alpha numeric, dashes, underscores and spaces

function validate_alpha($text)
{
    return preg_match("/^[A-Za-z0-9_- ]+$/", $text);
}

Validate US ZIP codes

function validate_zip($zip_code)
{
    return preg_match("/^([0-9]{5})(-[0-9]{4})?$/i",$zip_code);    
}


7。正則表達式的小抄
因為小抄現在是涼的,下面你可以找到一個小抄,可以運行通過,很快你忘了什么東西。

將文章分享到..
日本乱人伦一区| 中文字幕av网站| 国产欧美日韩中文久久| 最近免费中文字幕中文高清百度| 亚洲天堂日韩在线| 青青草免费在线视频观看| 国产伦久视频在线观看| 亚洲人成电影网站色www| freehdxxxx护士| 国产亚洲欧美一区二区| 美女视频黄免费的久久| 久久精品亚洲7777影院| 精品无人区一区二区三区| 日韩1区2区日韩1区2区| 国产sm主人调教女m视频| 精品国产免费久久| 久久精品人人爽| 欧美人善交videosg| 欧美日韩国产成人高清视频| 免费成年网站| 欧美国产二区| 超碰在线电影| 久久天天躁狠狠躁老女人| 狠狠色噜噜狠狠狠狠8888 | 日韩综合久久| 欧洲精品国产| 欧美国产一级| 一区二区视频免费看| 欧美视频久久| 少妇网站在线观看| 亚洲日本青草视频在线怡红院| 影音先锋中文字幕在线| 欧美在线视频播放| 超碰地址久久| 性色av无码久久一区二区三区| 午夜精品一区二区三区免费视频 | 五月激情丁香网| 国产精品久久久久永久免费观看 | 性孕妇free特大另类| 免费国产在线精品一区二区三区| 群体交乱之放荡娇妻一区二区| 久久发布国产伦子伦精品| 免费人成黄页网站在线一区二区 | 欧美日韩一视频区二区| 91女人18毛片水多国产| 亚洲福利影视| 三级全黄做爰视频| 国产成人久久久精品一区| 蜜臀av性久久久久蜜臀aⅴ流畅 | 成年人视频网址| 国产精品久久久久久久av电影| 成人在线视频观看| 国内精品卡一卡二卡三| 欧美午夜影院一区| 天堂免费在线视频| 日韩一区二区三区视频| 欧美二三四区| 精品一区二区无码| 久久久久久久av| 日本欧美不卡| 免费观看黄网站| 精品盗摄一区二区三区| 麻豆精品视频在线原创| 国产精品久久久久av福利动漫| 久久成人羞羞网站| 亚洲视频手机在线观看| 久久综合色视频| 亚洲精品视频在线播放| 久久精品国产精品青草| 丝袜美女写真福利视频| 久久久久久久穴| 久久久亚洲国产| 久久国产影院| 老熟妇一区二区三区啪啪| 亚洲经典中文字幕| 91成人在线精品视频| 亚洲最大成人av| 国产精品视频免费观看| 精品国产91| 国产一级特黄a高潮片| 亚洲精品在线免费播放| 欧美国产综合| 在线播放日本| 你懂得在线观看| 久久国产精品电影| 欧美综合二区| 性感av在线播放| 欧美在线激情| 在线一区免费| 成人c视频免费高清在线观看| 97成人在线免费视频| 国产日韩欧美一区二区三区综合| 欧美18hd| 麻豆91精品91久久久| 亚洲精品电影网站| 亚洲电影有码| 国产美女免费视频| 99久久综合狠狠综合久久止| 99久久免费国产| 二区中文字幕| 大地资源网在线观看免费官网 | 美女被黑人爆操网站| 91日韩视频在线观看| 欧美视频一区二区三区四区| 精品久久ai| 国产偷窥老熟盗摄视频| 日韩欧美亚洲在线| 亚洲国产专区| 怡红院在线播放| 在线观看色网站| 久久精品国产一区二区三区日韩| 国产**成人网毛片九色 | 四虎在线看片| 91成人免费看| 黄色日韩在线| 你懂的好爽在线观看| 日产亚洲一区二区三区| 亚洲xxxx18| 亚洲欧美一区二区久久| 久久一卡二卡| 黄网站色欧美视频| 欧美系列电影免费观看| av高清不卡| 男女无套免费网站| 老妇女50岁三级| 日本在线观看一区| 日韩高清人体午夜| 亚洲午夜在线| 717影院理论午夜伦不卡久久| 亚洲精品成人在线播放| 国产最新精品视频| 欧美性做爰猛烈叫床潮| 国产精品素人视频| 国产精品99久久不卡二区| 久久99国产精品尤物| 亚洲美女黄网| 女同性一区二区三区人了人一| 天堂a中文在线| 日韩精品视频免费播放| 色综合av综合无码综合网站| 日韩久久精品成人| 成人中文字幕合集| 男女视频在线| 四虎精品影院在线观看视频 | 午夜精品短视频| 欧美日韩国产综合视频在线观看 | 国产成人一二三区| 亚洲精品自拍视频| 亚洲图片欧美综合| 999国产在线视频| 91国产精品一区| 簧片在线免费看| 青娱乐国产91| 亚洲精品动漫100p| 亚洲欧美日本在线| 婷婷丁香久久五月婷婷| 福利一区福利二区微拍刺激| 激情成人在线视频| 亚洲欧洲精品一区二区三区 | 五月天婷亚洲天综合网鲁鲁鲁| 中文字幕不卡av| 国产精品欧美综合在线| 国产亚洲午夜| 欧美精品色图| 成视人a免费观看视频| 久久一区二区三| 日本精品久久久久久久久久| 国产精品小说在线| 中文欧美在线视频| 精品少妇v888av| 97久久精品国产| 亚洲色图日韩av| 欧美国产精品一区二区三区| 久久99热这里只有精品| 亚洲v在线看| 不卡一区综合视频| sm性调教片在线观看| 一区三区三区不卡| 四虎精品永久在线| 艳妇乳肉豪妇荡乳av| 国产传媒免费在线观看| 女教师淫辱の教室蜜臀av软件| 国产性猛交xx乱| 国产123在线| 长河落日免费高清观看| 午夜激情福利电影| 杨幂一区二区国产精品| 亚洲精品视频一区二区三区| 国产免费一区视频观看免费| 日韩av成人在线观看| 欧美理论片在线观看| 视频一区视频二区国产精品| 亚洲深夜福利在线| 日韩欧美福利视频| 国产精品久久久久7777按摩| 成人av电影在线网| 蜜臀久久99精品久久久久久9| 国产精品香蕉一区二区三区| 国产成人av福利| 91香蕉视频黄|