如何在没有 = 的情况下从 URL 获取变量?



所以我一直在谷歌上搜索

我现在可以做

index.php?action=something

但是我怎样才能做到

索引.php?某物

径直?

此致敬意

不使用htaccess的简单解决方案

<?php
IF (ISSET($_SERVER["REQUEST_URI"])){
$action = substr(strstr($_SERVER["REQUEST_URI"], "?"), 1);
switch ($action) {
case 'select':
echo "SELECT";
break;
case 'insert':
echo "INSERT";
break;
default:
echo "nothing";
break;
}
}
?>
<p><a href="index.php?select">action: select</a></p>
<p><a href="index.php?insert">action: insert</a></p>

在 htaccess 中粘贴此代码

RewriteRule ^index.php?(.+)$ index.php?action=$1

在您的 PHP 文件中

$term = $_GET['action'];

所以它会看起来像这样

https://example.com/index.php?something

最新更新