Edit report at https://bugs.php.net/bug.php?id=76950&edit=1
ID: 76950
Updated by: requinix@php.net
Reported by: tobias at tromm dot no-ip dot org
Summary: trim not working
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows Server 2016
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
Yes, it was converted. But for next time, familiarize yourself with functions like addcslashes so
that code CAN be copied and pasted.
$apelido = " \302\240 \302\240 \302\240 \302\240 \302\240 David \302\240 \302\240 \302\240
\302\240 \302\240 ";
The documentation for rtrim explicitly states what characters are trimmed by default. If you
don't like that list then provide your own.
Previous Comments:
------------------------------------------------------------------------
[2018-09-29 20:56:28] tobias at tromm dot no-ip dot org
PLEASE DONT COPY THESE CODE, IT WILL CHANGE THE RESULT COMPLETELY!!!
I just copy it and paste on my php editor and the result will change.
Use the zip file from the link I provide.
Otherwise, the space char will be converted!
------------------------------------------------------------------------
[2018-09-29 20:53:40] requinix@php.net
<?php
$apelido = "      David      ";
echo "Given String: \"".$apelido."\"<br><br>";
echo "Given String with the use of php trim function:
\"".trim($apelido)."\"<br><br>";
echo "Now we will check the ASCII table to check wich character are being
used:<br><br>";
for ($cont=0; $cont <strlen($apelido); $cont++){
echo "ORD: ".ord($apelido[$cont])."<br>";
}
$fazer = 1;
do {
$fazer = 0;
//Check the beginning of the string
if ($apelido[0] == chr(32) OR $apelido[0] == chr(194) OR $apelido[0] == chr(160)) {
$fazer = 1;
$apelido = ltrim($apelido, chr(32));
$apelido = ltrim($apelido, chr(194));
$apelido = ltrim($apelido, chr(160));
}
//Check the end of the string
if ($apelido[strlen($apelido)-1] == chr(32) OR $apelido[strlen($apelido)-1] == chr(194) OR
$apelido[strlen($apelido)-1] == chr(160)) {
$fazer = 1;
$apelido = rtrim($apelido, chr(32));
$apelido = rtrim($apelido, chr(194));
$apelido = rtrim($apelido, chr(160));
}
} while ($fazer == 1);
echo "<br>Result String:
\"".$apelido."\"<br><br>";
?>
------------------------------------------------------------------------
[2018-09-29 20:52:00] tobias at tromm dot no-ip dot org
I am afraid that if I copy the script here the characters will be converted and the result will
change.
Thas why I provide you a zip.
------------------------------------------------------------------------
[2018-09-29 20:48:47] tobias at tromm dot no-ip dot org
fix title
------------------------------------------------------------------------
[2018-09-29 20:46:52] requinix@php.net
If you have a repro script then include it in the report. Don't link us a .zip to download and
open.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76950
--
Edit this bug report at https://bugs.php.net/bug.php?id=76950&edit=1