我想剥离所有不在两个单词之间的空格吗?该脚本说明了一切:)str_replace php中的问题
$string = " bah bah bah ";
$string = str_replace("/w /w", "+", $string);
// i want string to look like this:
$string = "bah+bah+bah";
的想法是,我想摆脱所有不必要的空格(不仅在开头和结尾)
我想剥离所有不在两个单词之间的空格吗?该脚本说明了一切:)str_replace php中的问题
$string = " bah bah bah ";
$string = str_replace("/w /w", "+", $string);
// i want string to look like this:
$string = "bah+bah+bah";
的想法是,我想摆脱所有不必要的空格(不仅在开头和结尾)
难道你们就不能只是修剪空格和使用urlencode()
来将内部空间转换为+
?如果你有其他字符不能被URL编码,这是行不通的。但我们不知道你的全部要求。
urlencode(trim($string));
$string = " bah bah";
echo urlencode(trim($string));
// bah+bah
这就是我得到这个:“+++++++++++ bah + bah”..我正在寻找最简单的方法来得到这个:“bah + bah”; – faq
@ zolee3003你确定你在'urlencode()'中包含'trim()'吗?这对我来说很好。 –
我做了一个测试,它也可以工作。 – armandomiani
$string = str_replace("/w /w", "+", trim($string));
装饰()删除所有不必要的空格
trim将删除空格开头和结尾:
$string = trim($string);
echo str_replace(" ", "+", $string);
你会使用这个网址内部? – armandomiani
它是一个搜索框 – faq
我删除了空间后,我想爆炸它(但已经完成) – faq