所以我目前有一系列字符串。他们可能有访问空格,所以我想通过将“book”变成“book”来摆脱它。但是,如果我使用trim,那么诸如“some title”之类的字符串就会变成“sometitle”。我该怎么做?
答案 0 :(得分:2)
Trim是您正在寻找的功能,文档here。与你所说的相反:
trim — Strip whitespace (or other characters) from the beginning and end of a string
中间将不受影响!
答案 1 :(得分:0)
$str[] = " book ";
$str[] = " book";
$str[] = "book ";
$str[] = "b o o k";
foreach($str as $s){
echo trim($s).'<br>';
}
trim()在空白之前和之后削减。永远不会在中间。
答案 2 :(得分:0)