簡體   English   中英

URL PHP中的正則表達式

[英]Regular Expression in URL php

我有以下代碼來確定要與Codeigniter一起使用的默認控制器。

if ($_SERVER['HTTP_HOST']=="5409.gs.mycoolurl.org") {

   $route['default_controller'] = 'new-site/newsite'; 
}
else {

   $route['default_controller'] = '';
}

問題是在5409.gs. 5409將是隨機的,但始終為4位數字。 我如何在此if語句中允許任何4位數字和.gs? 我努力了:

[0-9].gs.mycoolurl.org但總是有else問題。

if (preg_match("/\d{4}\.gs/", $_SERVER['HTTP_HOST'])) {

$route['default_controller'] = 'new-site/newsite'; 

說明

\d{4} match a digit [0-9]
Quantifier: Exactly 4 times
\. matches the character . literally
gs matches the characters gs literally (case sensitive)

嘗試這個 :

\\d{4}.gs

\\ d是數字

{4}的范圍是4

https://docs.python.org/2/library/re.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM