之间规定我有一个字符串:删除空格,不包括这些指定的字符
Some string, "it's a nice string". I like it. "some other text"
我想删除空格,不包括有beetween“:
Somestring,"it's a nice string".Ilikeit."some other text"
我怎么能进球呢?
之间规定我有一个字符串:删除空格,不包括这些指定的字符
Some string, "it's a nice string". I like it. "some other text"
我想删除空格,不包括有beetween“:
Somestring,"it's a nice string".Ilikeit."some other text"
我怎么能进球呢?
你可以使用正则表达式,或者你可以欺骗和利用explode()
:
阿之间ommit那里,你打我!干得好:d – Grexis 2011-12-21 12:06:35
也许吧,但你的解决方案是清洁:) – 2011-12-21 12:15:03
您可以使用PHP str_replace函数的功能实现。请检查http://php.net/manual/en/function.str-replace.php
我不擅长用正则表达式,因此该方案不使用任何。我会做什么:
$str = 'Some string, "it\'s a nice string". I like it. "some other text"';
$pieces = explode('"', $str);
for($i = 0; $i < count($pieces); $i += 2){ // Every other chunk is quoted
$pieces[$i] = str_replace(' ', '', $pieces[$i]);
}
$str = implode('"', $pieces);
如果字符串以双引号开始,PHP将使$pieces
阵列空的第一个元素,所以这应该仍然工作。
通过处理字符串,删除的空间。查看PHP字符串函数和正则表达式。 – hakre 2011-12-21 11:55:16
你有什么到目前为止已经试过?你被拒绝投票,因为没有表现出我相信这样做的任何努力。 – Hammerstein 2011-12-21 12:18:53
是啊,我想正则表达式,但我只能删除所有空格,我不知道如何标记 – PiKey 2011-12-21 12:45:23