Type of $_GET variable

夙愿已清 提交于 2020-08-11 01:13:51

问题


I have this rewriterule in .htaccess file

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

Then, when I check type of $_GET['url'], is always a string.

I interested to know whether or not it's possible, to write in the browser's address bar some magic symbols (or something like this) and obtain in $_GET['url'] an other type (not string)?

Or will the type of $_GET always be string?


回答1:


If you do this:

 index.php?url=asd&url[]=asd //asd&url[]=asd being the dynamic part

Then $_GET['url'] will be an array.




回答2:


Whatever you take from $_GET will always be a string.




回答3:


$_GET parameters will always be strings.

But you could check if your variable is a number, and then use a cast:

if (is_numeric($_GET['url'])) {
  $url = (int) $_GET['url'];
}

http://php.net/manual/en/function.is-numeric.php

http://php.net/manual/en/language.types.type-juggling.php



来源:https://stackoverflow.com/questions/13388933/type-of-get-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!