How to use less variables with $_GET
I've noticed that instead of using:
http://yoursite.com/index.php?page=4
I could just use:
http://yoursite.com/index.php?4
How to do this in php and JavaScript?
In the example you have posted, now 4
is the key instead of value.
If you are passing ONLY one parameter via query string this is doable,otherwise you wont know in PHP what is what without a key for your parameter.
In the particular example you can get it like this in PHP
$id = null
if(!empty($_GET)){
$keys = array_keys($_GET);
// verify that the first key contains only digits, and use it as id
// ctype_digit does not work here because the key is now an int so use is_numeric
if(is_numeric($keys[0]))
$id = $keys[0];
}
I do not know what do you want to do in Javascript here.
Also if you are trying to generate SEO friendly URLs I would suggest that you look into URL Rewriting.
$page = $_SERVER['QUERY_STRING'];
精彩评论