• <tfoot id='irAci'></tfoot>

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

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

      1. <legend id='irAci'><style id='irAci'><dir id='irAci'><q id='irAci'></q></dir></style></legend>

        检查字符串是否以 PHP 中的数字结尾

        Check if a String Ends with a Number in PHP(检查字符串是否以 PHP 中的数字结尾)

        <legend id='gdtj7'><style id='gdtj7'><dir id='gdtj7'><q id='gdtj7'></q></dir></style></legend>
      2. <tfoot id='gdtj7'></tfoot>

          • <bdo id='gdtj7'></bdo><ul id='gdtj7'></ul>

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

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

                <tbody id='gdtj7'></tbody>

                1. 本文介绍了检查字符串是否以 PHP 中的数字结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试实现以下功能.最好在这里使用某种类型的正则表达式吗?我也需要获取号码.

                  I'm trying to implement the function below. Would it be best to use some type of regex here? I need to capture the number too.

                  function endsWithNumber($string) {
                    $endsWithNumber = false;
                  
                    // Logic
                  
                    return $endsWithNumber;
                  }
                  

                  推荐答案

                  $test="abc123";
                  //$test="abc123n";
                  $r = preg_match_all("/.*?(d+)$/", $test, $matches);
                  //echo $r;
                  //print_r($matches);
                  if($r>0) {
                      echo $matches[count($matches)-1][0];
                  }
                  

                  正则表达式解释如下:

                  .*?- 这将从一开始就占用字符串中的所有字符,直到也找到后续部分的匹配项.

                  .*? - this will take up all the characters in the string from the start up until a match for the subsequent part is also found.

                  (d+)$ - 直到字符串末尾的一位或多位数字,已分组.

                  (d+)$ - this is one or more digits up until the end of the string, grouped.

                  没有 ?在第一部分中,只有最后一个数字将在第二部分中匹配,因为它之前的所有数字都会被 .* 占用.*

                  without the ? in the first part, only the last digit will be matched in the second part because all digits before it would be taken up by the .*

                  这篇关于检查字符串是否以 PHP 中的数字结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Converting between timezones in PHP(在 PHP 中的时区之间转换)
                  PHP - strtotime, specify timezone(PHP - strtotime,指定时区)
                  Get current date, given a timezone in PHP?(获取当前日期,给定 PHP 中的时区?)
                  List of US Time Zones for PHP to use?(PHP 使用的美国时区列表?)
                  How to detect Ambiguous and Invalid DateTime in PHP?(如何在 PHP 中检测不明确和无效的 DateTime?)
                  How to update timezonedb in PHP (updating timezones info)?(如何在 PHP 中更新 timezonedb(更新时区信息)?)

                  <legend id='GffVJ'><style id='GffVJ'><dir id='GffVJ'><q id='GffVJ'></q></dir></style></legend>
                    <bdo id='GffVJ'></bdo><ul id='GffVJ'></ul>

                        <tbody id='GffVJ'></tbody>

                        <tfoot id='GffVJ'></tfoot>

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

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