删除字符串php中的数字

问题描述 投票:0回答:1

我有特定的字符串

$email = "[email protected]";

我想清理并从字符串中删除+1,它也可以是任何数字+1或+99,因此最终的字符串可以是

$email = "[email protected]";

我不知道该怎么办,我尝试创建此方法,但是它给了我这个输出。

$email = jaymingmail.com;

下面是我的功能:

public function delete_all_between($beginning, $end, $string) {
      $beginningPos = strpos($string, $beginning);
      $endPos = strpos($string, $end);
      if ($beginningPos === false || $endPos === false) {
        return $string;
      }

      $textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);

      return $this->delete_all_between($beginning, $end, str_replace($textToDelete, '', $string)); // recursion to ensure all occurrences are replaced
    }


$out = $this->delete_all_between('+', '@', $email);

谁能帮我解决我要去的地方。

我需要删除+1或+号后的任何数字。

php laravel preg-replace
1个回答
1
投票
您可以使用preg_replace用一行完成它
© www.soinside.com 2019 - 2024. All rights reserved.