Re: Agh! trim (#$@#@^%!!!)
| From: | Justin French | Date: | Tue, 20 Aug 2002 16:49:56 +0000 |
| Subject: | Re: Agh! trim (#$@#@^%!!!) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-113363@lists.php.net to get a copy of this message | ||
> $single = "The date is 20-Aug-2002." // This is an example - see below
> $trimmed = rtrim($date, ".");
Where is $date? I think your attempting to trim the wrong string.
This worked for me:
<?
$single = "The date is 20-Aug-2002.";
$trimmed = rtrim($single, ".");
echo $trimmed;
?>
To slice off the last character of any string, you could use substr():
<?
$single = "The date is 20-Aug-2002.";
$trimmed = substr($single, 0, -1);
echo $trimmed;
?>
Justin French
on 21/08/02 2:35 AM, Mike At Spy (spycobalt@spyproductions.com) wrote:
>
> Hey!
>
> :)
>
> I have an issue with trim / triml. Whenever I put a string in to trimmed,
> it refuses to take the period at the end of the string off.
>
> I did put more things to trim first, but this is basically what I am doing:
>
>
> $single = "The date is 20-Aug-2002." // This is an example - see below
> $trimmed = rtrim($date, ".");
>
>
> Is there an issue with this? I've tried using trim() too.
>
> The source of $single is a reponse from a server. I should note that when I
> put this in as an experiment, it works fine. When I get the line from the
> server, it doesn't work!
>
> The only thing I can think of is the possibility that the "." I am seeing at
> the end of the line isn't really one (it looks like a duck, copies like a
> duck, but...isn't a duck??!!).
>
> Is there a way to just strip the last character off regardless of what it
> is?
>
> Thanks,
>
> -Mike
>
>