The following code:
下面的代码:
<?php
$str='Who are you?';
echo chop($str,'you?').'<br>';
echo chop($str,'are you?').'<br>';
?>
gives me the output:
给我输出:
Who are
Wh
Why the second output is
为什么第二个输出是
Wh
and not
而不是
who
2 个解决方案
#1
8
because:
因为:
(PHP 4, PHP 5, PHP 7)
chop
— Alias ofrtrim()
(PHP 4, PHP 5, PHP 7) rtrim()别名
and
和
(PHP 4, PHP 5, PHP 7)
rtrim
— Strip whitespace (or other characters) from the end of a string(PHP 4、PHP 5、PHP 7) rtrim——字符串末尾的空格(或其他字符)
string rtrim ( string $str [, string $character_mask ] )
字符串rtrim (string $str [, string $character_mask])
So... you're feeding a character mask.
所以…你在喂一个人物面具。
Given that, "o" is in that mask, so it gets trimmed out
假设"o"在蒙版中,所以它会被删除
#2
2
In your string you have specified a character_mask
, this is what reference says:
在您的字符串中指定了一个characters _mask,引用如下:
character_mask: You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.
还可以通过characters _mask参数指定要剥离的字符。只需列出您想要删除的所有字符。与. .您可以指定字符的范围。
In your case, there's an 'o' in the mask, for this reason all 'o' in $str
have been deleted.
在你的例子中,面具中有一个“o”,因为这个原因,$str中的所有“o”都被删除了。
#1
8
because:
因为:
(PHP 4, PHP 5, PHP 7)
chop
— Alias ofrtrim()
(PHP 4, PHP 5, PHP 7) rtrim()别名
and
和
(PHP 4, PHP 5, PHP 7)
rtrim
— Strip whitespace (or other characters) from the end of a string(PHP 4、PHP 5、PHP 7) rtrim——字符串末尾的空格(或其他字符)
string rtrim ( string $str [, string $character_mask ] )
字符串rtrim (string $str [, string $character_mask])
So... you're feeding a character mask.
所以…你在喂一个人物面具。
Given that, "o" is in that mask, so it gets trimmed out
假设"o"在蒙版中,所以它会被删除
#2
2
In your string you have specified a character_mask
, this is what reference says:
在您的字符串中指定了一个characters _mask,引用如下:
character_mask: You can also specify the characters you want to strip, by means of the character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters.
还可以通过characters _mask参数指定要剥离的字符。只需列出您想要删除的所有字符。与. .您可以指定字符的范围。
In your case, there's an 'o' in the mask, for this reason all 'o' in $str
have been deleted.
在你的例子中,面具中有一个“o”,因为这个原因,$str中的所有“o”都被删除了。