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