精華區beta RegExp 關於我們 聯絡資訊
請問下面這個 preg_match 的用法怎麼拆解? /** * Validate that a hostname (for example $_SERVER['HTTP_HOST']) is safe. * * As $_SERVER['HTTP_HOST'] is user input, ensure it only contains characters * allowed in hostnames. See RFC 952 (and RFC 2181). $_SERVER['HTTP_HOST'] is * lowercased. * * @return * TRUE if only containing valid characters, or FALSE otherwise. */ function drupal_valid_http_host($host) { return preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $host); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.186.59 > -------------------------------------------------------------------------- < 作者: LPH66 ((short)(-15074)) 看板: RegExp 標題: Re: [問題] 語法請教 時間: Sun Nov 22 22:57:02 2009 ※ 引述《tonytsai88 (我愛吃涼麵)》之銘言: : 請問下面這個 preg_match 的用法怎麼拆解? : /** : * Validate that a hostname (for example $_SERVER['HTTP_HOST']) is safe. : * : * As $_SERVER['HTTP_HOST'] is user input, ensure it only contains characters : * allowed in hostnames. See RFC 952 (and RFC 2181). $_SERVER['HTTP_HOST'] is : * lowercased. : * : * @return : * TRUE if only containing valid characters, or FALSE otherwise. : */ : function drupal_valid_http_host($host) { : return preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $host); 分隔線 / / 字首 ^ 就是個[ \[ 或者沒有 ? 這個括號不計入back-ref (?: ) 這一些字 [a-z0-9-:\]_] 有一個以上 + 就是個. \. 或者沒有 ? 以上的括號有一個以上 + 字尾 $ : } (?: ) 的說明在這裡: http://tw.php.net/manual/en/regexp.reference.subpatterns.php 第五段就是了 -- 有人喜歡邊玩遊戲上逼; 也有人喜歡邊聽歌打字。 但是,我有個請求, 選字的時候請專心好嗎? -- 改編自「古 火田 任三郎」之開場白 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.28.92
tonytsai88:感恩 11/23 00:15
cutecpu:推! 11/23 12:45