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 #171941 is a reply to message #171939] Sat, 22 January 2011 02:16 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 22/01/11 01:52, GarryJones wrote:
>> $source = preg_replace("/[#*]+/g","",$source);
>> // $source is replaced with filtered $source
>
> I can't get this example to work.
>
> $source = "garry *** ";
> $source = preg_replace("/[#*]+/g","",$source);
>
> print $source;
>
> ....returns an empty string

Oops, doesn't need the g modifier.

Try:

$source = preg_replace("/[#*]+/","",$source);

> record 1 "Garry ### "
> record 2 "John * "
> record 3 "Anna ********"
> record 4 "Fred **#*###**"

<?php
$recs = array("Garry ### ","John * ","Anna ********","Fred **#*###**");
foreach ($recs as $str) print trim($str, " \t\n\r\0\x0B*#") . "\n";
?>

Garry
John
Anna
Fred

Rgds

Denis McMahon
[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 03:16:12 GMT 2024

Total time taken to generate the page: 0.04035 seconds