/    Sign up×
Community /Pin to ProfileBookmark

What’s Different Between rtrim() and chop() ?

PHP Folks,

I don’t see any difference between these two functions in my tests:

“””‘
<?php
echo ‘<b>Line: ‘ .__LINE__ .'</b>’; echo ‘<br>’;
echo chop(‘motorbike’,’bike’);
echo ‘<br>’;
echo chop(‘motor bike’,’bike’);
echo ‘<br>’; echo ‘<br>’;
?>

<?php
echo ‘<b>Line: ‘ .__LINE__ .'</b>’; echo ‘<br>’;
echo chop(‘motorbike’,’motor’);
echo ‘<br>’;
echo chop(‘motor bike’,’motor’);
echo ‘<br>’; echo ‘<br>’;
?>

<?php
echo ‘<b>Line: ‘ .__LINE__ .'</b>’; echo ‘<br>’;
echo rtrim(‘motorbike’,’bike’);
echo ‘<br>’;
echo rtrim(‘motor bike’,’bike’);
echo ‘<br>’; echo ‘<br>’;
?>

<?php
echo ‘<b>Line: ‘ .__LINE__ .'</b>’; echo ‘<br>’;
echo rtrim(‘motorbike’,’motor’);
echo ‘<br>’;
echo rtrim(‘motor bike’,’motor’);
echo ‘<br>’; echo ‘<br>’;
?>
“””

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 06.2021 — It's amazing what you can learn if you RTFM.

https://www.php.net/chop :
> This function is an alias of: rtrim().
Copy linkTweet thisAlerts:
@developer_webauthorFeb 11.2021 — @NogDog#1627689

Oh bluddy hell NogDog! Ha! Ha!

Why the hell didn't w3schools.com just mention one is alias of another ? Drat!

Anyway, thanks for pointing this out to me.
Copy linkTweet thisAlerts:
@DigiturnalFeb 17.2021 — Hi Php Folks,

The rtrim() function removes whitespace or other predefined characters from the right side of a string. Related functions: ltrim() - Removes whitespace or other seeded characters from the left side of a string.

The chop() function in Perl is used to remove the last character from the input string. Syntax: chop(String) Parameters: String : It is the input string whose last characters are removed.

Returns: the last removed character.

Copy linkTweet thisAlerts:
@marksmith121Feb 17.2021 — In terms of functionality there is (currently) no difference. They will both (currently) work the same as one is simply an alias of the other.

Copy linkTweet thisAlerts:
@HarshShahFeb 23.2021 — Both chop() and rtrim() are used to remove whitespace and predefined characters from the right side of a string. The chop() function is the alias of rtrim() function.
Copy linkTweet thisAlerts:
@VITSUSAFeb 23.2021 — @marksmith121#1628151 Why you are doing copy paste the answer from mentioned source?

https://stackoverflow.com/questions/28495291/chop-vs-rtrim#:~:text=Is%20there%20any%20difference%20between,an%20alias%20of%20the%20other.
Copy linkTweet thisAlerts:
@developer_webauthorFeb 25.2021 — @VITSUSA#1628391

I thought you were asking me the question. I went to stackoverflow.com and see the question is different, even if topic same. Was gonna ask you if you were high (under drug influence) or not. But then realise you were asking someone else. Now ask me if I am high or not.

Answer: it's past midnight and I'm nodding on my chair! Lol.
Copy linkTweet thisAlerts:
@VITSUSAFeb 26.2021 — @developer_web#1628525 You should read carefully which I have mentioned in the post. @marksmith121 has copied the answer from the source which I have mentioned in the post.

I think you should not support wrong things. I will pray to god, you will understand the sense:)
Copy linkTweet thisAlerts:
@developer_webauthorFeb 26.2021 — @VITSUSA#1628554

I am not supporting him. You understood wrong. Later, I found him doing same in another thread of mine and he got a warning from NogDog.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...