Home  >  Article  >  Backend Development  >  How to remove numbers from string in php

How to remove numbers from string in php

coldplay.xixi
coldplay.xixiOriginal
2020-10-08 16:17:002046browse

php去除字符串中数字的方法:首先创建一个PHP示例文件;然后通过【$class=preg_replace("/\\d+/",'', $res);】方法实现去掉字符串的数字即可。

How to remove numbers from string in php

php去除字符串中数字的方法:

方法简单,代码为:

$class=preg_replace("\\d+",'', $res);

需要使用preg_replace函数,但是只是这么写的话,会报错

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash

翻译过来就是定界符不能是字母数字或反斜线。

想了一下,在正则表达式首尾加了一对/

$class=preg_replace("/\\d+/",'', $res);

想了解更多编程学习,敬请关注php培训栏目!

The above is the detailed content of How to remove numbers from string in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn