删除 php 字符串中所有不必要的空格
我想删除所有不在两个字母之间的空格:
$string = " bah bah bah bah ";
$string = str_replace("/w /w", "+", $string);
// what goes here? to get this:
$string = "bah+bah+bah+bah";
这个想法是我想删除所有不必要的空格(不仅在开头和结尾)。这不是一个链接,而是一个搜索框,提交时会分解,所以 + 甚至可以是 = 或任何基本上
I want to strip all spaces that are not between two letters:
$string = " bah bah bah bah ";
$string = str_replace("/w /w", "+", $string);
// what goes here? to get this:
$string = "bah+bah+bah+bah";
The idea is that i want to get rid of all unnecessary spaces(not only at the beginning and end). This is not for a link but for a search box that on submit will be exploded so the + can even be a = or anything basically
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的最终目标是分解搜索字符串(即分解为一组术语),我建议使用
preg_split()
If your ultimate goal is to explode a search string (i.e. into an array of terms) I suggest condensing all steps into one using
preg_split()