FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Syntax for trim charlist?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Syntax for trim charlist? [message #171944 is a reply to message #171935] Sat, 22 January 2011 03:09 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 1/21/2011 6:35 PM, GarryJones wrote:
> I need to trim away * and # in a list of names.
>
> First I want to get rid of the standard funny stuff so I do this.
>
> $mytrim1 = trim($mytext);
>
> Now I need to remove all the * and the # and this is where I am stuck.
>
> The syntax on php.net says to use "string trim ( string $str [, string
> $charlist ] )"
>
> As in $mytrim2 = trim($mytrim2, $charlist);
>
> Countless complex examples are given but nowhere I can find an
> explantion of how to write $charlist - I just need to trim all the *
> and the # from this list of names.
>
> So bottom line, how do I set $charlist to just omit the * and the #
>
> Can these characters be added to the first "standard" trim to cut the
> code down to one row?
>
> And question 2. Is there a "php made simple" website. I just wanted a
> simple standard explanation. I find I am always looking at massive
> complex solutions in the examples on php.net. All very useful I am
> sure but I need to learn to walk before I can run.
>
> Any help greatly appreciated.
>
> Garry Jones
> Sweden

It's just a list of characters you want trimmed from the front and end
of a string, i.e.

$str1 = '#*It works *# #* *#';
$str2 = trim($str1, '#* ');
echo $str;

prints "It works"

Be sure to add a space character in case you have one at the end. And
while you can use a regex, it's way overkill for something this simple.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Implement Php performace
Next Topic: Is there any situation where anything other than require_once is better?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 02:16:01 GMT 2024

Total time taken to generate the page: 0.04541 seconds