PHP中如何移除字符串中的破折号(-)?
- 内容介绍
- 文章标签
- 相关推荐
本文共计586个文字,预计阅读时间需要3分钟。
三种方法:1. 使用 `str_replace('-','',$str)` 将-替换为空格;2. 使用 `preg_replace('/-/', '', $str)` 通过正则表达式查找并去除-;3. 使用 `preg_filter('/-/', '', $str)` 去除-。操作环境:Windows。
3种方法:1、使用“str_replace("-",'',$str)”将“-”字符替换为空字符;2、用“preg_replace("/-/","",$str)”执行正则表达式来查找“-”字符并将去除;3、用preg_filter()来去除。
本教程操作环境:windows7系统、PHP8.1版、DELL G3电脑
php字符串去掉“-”字符的方法
方法1:使用str_replace()或str_replace() 函数
str_ireplace() 和 str_replace 使用新的字符串替换原来字符串中指定的特定字符串,str_replace 区分大小写,str_ireplace() 不区分大小写,两者语法相似。
只需将“-”字符替换为空字符''即可。
本文共计586个文字,预计阅读时间需要3分钟。
三种方法:1. 使用 `str_replace('-','',$str)` 将-替换为空格;2. 使用 `preg_replace('/-/', '', $str)` 通过正则表达式查找并去除-;3. 使用 `preg_filter('/-/', '', $str)` 去除-。操作环境:Windows。
3种方法:1、使用“str_replace("-",'',$str)”将“-”字符替换为空字符;2、用“preg_replace("/-/","",$str)”执行正则表达式来查找“-”字符并将去除;3、用preg_filter()来去除。
本教程操作环境:windows7系统、PHP8.1版、DELL G3电脑
php字符串去掉“-”字符的方法
方法1:使用str_replace()或str_replace() 函数
str_ireplace() 和 str_replace 使用新的字符串替换原来字符串中指定的特定字符串,str_replace 区分大小写,str_ireplace() 不区分大小写,两者语法相似。
只需将“-”字符替换为空字符''即可。

