Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中查找字符串? 输入文本和数字:_Php - Fatal编程技术网

如何在php中查找字符串? 输入文本和数字:

如何在php中查找字符串? 输入文本和数字:,php,Php,试试这个 <form name="search" method="post" > Input texts and numbers: <input type="text" name="find"><br> </form> <?php if(!empty($_POST)){ echo $_POST['find']; } 您可以在结束前去掉所有数字: $str = "123mynumber11"; do { $n =

试试这个

<form name="search" method="post" >
Input texts and numbers: <input type="text" name="find"><br>
</form>
<?php
 if(!empty($_POST)){
   echo $_POST['find'];    
 }

您可以在结束前去掉所有数字:

$str = "123mynumber11";

do
{
    $n = substr($str,-1);
    if(is_numeric($n))
        $str = substr($str,0,-1);
}
while(is_numeric($n));

echo($str);
您可以使用:


只是想澄清一下,你想去掉最后11个。如果最后两个数字是11,你想去掉吗?我想去掉文本后的所有数字,如果输入是'232mytext3455',那么它会显示'232mytext'@chandresh_很酷正如前面提到的,没有必要发表评论来通知某人你的答案。我想保留文本前的数字。是的,上面会这样做,它只是删除了文本末尾的数字。在我看来,正则表达式对于这些简单的事情来说太过分了。@Jack;非常感谢您修复了代码中的语法问题。rtrim将删除字符串末尾指定的空格和字符。
if(!empty($_POST))
    $findStr = preg_replace('/\d+$/', '', $_POST['find']);
echo rtrim($_POST['find'], '1234567890');