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 #171945 is a reply to message #171935] Sat, 22 January 2011 03:15 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

Another thought - if you need to replace the characters throughout the
string, instead of just beginning and end, use str_replace, i.e.

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

also prints "It works"

--
==================
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: Tue Nov 26 16:32:14 GMT 2024

Total time taken to generate the page: 0.03556 seconds