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 #171993 is a reply to message #171945] Wed, 26 January 2011 10:08 Go to previous message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma:
Member
Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:

> 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.

<snip>

>> 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?

<snip>

> 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;

ITYM "echo $str2;"

If you want to replace "#" and "*" throughout the string /and/ to
trim extraneous whitespace at the beginning or end of your string,
you can call trim() on the string returned by str_replace():

$str1 = ' *foo* bar## ';
$str2 = trim(str_replace(array('#','*'), '', $str1));
echo $str2;

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
[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: Wed Nov 27 03:44:24 GMT 2024

Total time taken to generate the page: 0.05575 seconds