• <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 中的数字结尾

        时间:2024-08-15

        <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 中的数字结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP 将数字缩写(5.2k、1.7m 等)转换为有效整数 下一篇:PHP json_decode 整数和浮点数到字符串

                  相关文章

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

                2. <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'>