php - 我如何删除在php中两边都有空格的连字符
问题描述
这是我要删除的带有连字符的字符串,但两边都有空格
Year 7 Scheme of Learning – Lord of the Flies/Transactional Writing HAO
解决方案
我会使用 str_replace https://www.php.net/manual/en/function.str-replace.php
$string = "Year 7 Scheme of Learning – Lord of the Flies/Transactional Writing HAO";
// remove spaces and hyphen
$newString = str_replace(" - ","",$string);
// remove 1 space and hyphen
$newString = str_replace(" -","",$string);
// remove hyphen
$newString = str_replace("-","",$string);
推荐阅读
- python - 循环需要很长时间才能运行
- python - 使用 astropy 时的 Numpy 版本问题
- angular - 如何在 Angular 反应形式和验证器中使用货币管道
- c++ - Accessing functions of a derived crtp class from the base calls
- sql - 尝试使用 Spring-jpa 计算两个时间戳之间的差异时出错?
- react-native - 如何获取 Expo 静态深度链接进行开发?
- scala - Filtering dataframe spark scala for dates greater than current time
- python - Python Tkinter - 是否可以链接两个单独网格的几何管理器
- java - 如何将闹钟应用程序与您的电子管连接?
- python - 如何使用熊猫连接数据框中部分顺序出现的行