PHP: chop - Manual (original) (raw)
(PHP 4, PHP 5, PHP 7, PHP 8)
chop — Alias of rtrim()
Description
This function is an alias of: rtrim().
Notes
Note:
chop() is different than the Perl
chop()function, which removes the last character in the string.
Found A Problem?
10 years ago
Rather use rtrim(). Usage of chop() is not very clear nor consistent for people reading the code after you.
10 years ago
If you are searching for a function that does the same trick as chop in PERL, then you should just do the following code:
<?php
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>t</mi><mi>r</mi><mo>=</mo><mi>s</mi><mi>u</mi><mi>b</mi><mi>s</mi><mi>t</mi><mi>r</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">str = substr(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6151em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">u</span><span class="mord mathnormal">b</span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mopen">(</span></span></span></span>str, 0, -1);
?>
The question is: why isn't chop() an alias of the code above, rather than something which will trap developpers?