• <legend id='5ZUf6'><style id='5ZUf6'><dir id='5ZUf6'><q id='5ZUf6'></q></dir></style></legend>

    <small id='5ZUf6'></small><noframes id='5ZUf6'>

        <tfoot id='5ZUf6'></tfoot>
          <bdo id='5ZUf6'></bdo><ul id='5ZUf6'></ul>
      1. <i id='5ZUf6'><tr id='5ZUf6'><dt id='5ZUf6'><q id='5ZUf6'><span id='5ZUf6'><b id='5ZUf6'><form id='5ZUf6'><ins id='5ZUf6'></ins><ul id='5ZUf6'></ul><sub id='5ZUf6'></sub></form><legend id='5ZUf6'></legend><bdo id='5ZUf6'><pre id='5ZUf6'><center id='5ZUf6'></center></pre></bdo></b><th id='5ZUf6'></th></span></q></dt></tr></i><div id='5ZUf6'><tfoot id='5ZUf6'></tfoot><dl id='5ZUf6'><fieldset id='5ZUf6'></fieldset></dl></div>

        如何检查 $_GET Array 中的变量是否为整数?

        How to check whether a variable in $_GET Array is an integer?(如何检查 $_GET Array 中的变量是否为整数?)

            <tbody id='FaSXs'></tbody>

            <bdo id='FaSXs'></bdo><ul id='FaSXs'></ul>
              <i id='FaSXs'><tr id='FaSXs'><dt id='FaSXs'><q id='FaSXs'><span id='FaSXs'><b id='FaSXs'><form id='FaSXs'><ins id='FaSXs'></ins><ul id='FaSXs'></ul><sub id='FaSXs'></sub></form><legend id='FaSXs'></legend><bdo id='FaSXs'><pre id='FaSXs'><center id='FaSXs'></center></pre></bdo></b><th id='FaSXs'></th></span></q></dt></tr></i><div id='FaSXs'><tfoot id='FaSXs'></tfoot><dl id='FaSXs'><fieldset id='FaSXs'></fieldset></dl></div>

                1. <tfoot id='FaSXs'></tfoot>

                  <small id='FaSXs'></small><noframes id='FaSXs'>

                  <legend id='FaSXs'><style id='FaSXs'><dir id='FaSXs'><q id='FaSXs'></q></dir></style></legend>
                2. 本文介绍了如何检查 $_GET Array 中的变量是否为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个这样的页面:

                  http://sitename/gallery.php?page=2

                  底部有分页链接,我们可以通过这些链接进行浏览.每次点击页码时,它都会发送一个带有参数 page=1page=2 等的 GET 请求......

                  It has pagination links at the bottom by which we can browse. Everytime the page numbers are clicked, it would send a GET request with parameters page=1 or page=2 and so on ...

                  当我将这些值从 $_GET 变量存储到 $page 时,它是一个字符串值.我可以像这样使用 (int) 将其转换为整数:

                  When I store these values to $page from teh $_GET variable, it is a string value. I can convert it to an integer using (int) like this:

                  if(!empty($_GET['page'])){
                         $page = (int)$_GET['page'];
                         echo "Page Number: ".$page;
                  }
                  

                  但是我如何确保传递的值是整数而不是其他垃圾?

                  But how can I make sure that the value passed is an integer only and not other crap?

                  推荐答案

                  使用过滤器:

                  if (null !== ($page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE))) {
                      // $page is now an integer
                  }
                  

                  这还会检查变量是否同时出现在查询字符串中.如果你想区分缺失和无效,你必须去掉 filter_input() 的最后一个参数:

                  This also checks whether the variable appears in the query string at the same time. If you want to differentiate between missing and invalid you have to leave off the last argument to filter_input():

                  $page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
                  // $page can be null (not present), false (present but not valid) or a valid integer
                  

                  这篇关于如何检查 $_GET Array 中的变量是否为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)
                      <tfoot id='90OBi'></tfoot>
                        <bdo id='90OBi'></bdo><ul id='90OBi'></ul>

                        <small id='90OBi'></small><noframes id='90OBi'>

                            <i id='90OBi'><tr id='90OBi'><dt id='90OBi'><q id='90OBi'><span id='90OBi'><b id='90OBi'><form id='90OBi'><ins id='90OBi'></ins><ul id='90OBi'></ul><sub id='90OBi'></sub></form><legend id='90OBi'></legend><bdo id='90OBi'><pre id='90OBi'><center id='90OBi'></center></pre></bdo></b><th id='90OBi'></th></span></q></dt></tr></i><div id='90OBi'><tfoot id='90OBi'></tfoot><dl id='90OBi'><fieldset id='90OBi'></fieldset></dl></div>

                          • <legend id='90OBi'><style id='90OBi'><dir id='90OBi'><q id='90OBi'></q></dir></style></legend>
                              <tbody id='90OBi'></tbody>