PHP's chop () string function does not give desired result

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 is the second conclusion

Wh

      

but not

who

      

+3


source to share


2 answers


because:

(PHP 4, PHP 5, PHP 7)
chop

- Aliasrtrim()

and



(PHP 4, PHP 5, PHP 7)
rtrim

- strip spaces (or other characters) from end of line

string rtrim ( string $str [, string $character_mask ] )

So ... you feed the character's mask.

Considering "o" is in this mask, so it gets cropped

+8


source


In your line you specified character_mask

, this is what it says:

character_mask : You can also specify the characters you want to split using the character_mask parameter. Just list all the characters you want to remove. With .. you can specify a range of characters.



In your case, there is an "o" in the mask, for this reason all the "o" s $str

have been removed.

+2


source







All Articles