Re: Reg Exp help needed
| From: | Don Read | Date: | Tue, 24 Jun 2003 19:39:45 +0000 |
| Subject: | Re: Reg Exp help needed | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-152652@lists.php.net to get a copy of this message | ||
On 24-Jun-2003 Sparky Kopetzky wrote:
> I'm translating (hacking) code from Perl to PHP and have two reg exp
> expressions I can't figure out what they do.
>
> 1st: $goodbadnum =~ tr/0-9//cd; I think this one removes any chars that
> are not numbers.
>
Nope. That removes digits '0-9'
$goodbadnum= preg_replace('!\d+!', '', $goodbadnum);
> 2nd: $goodbadnum =~ tr/0-9/x/; I think this one replaces and numbers with
> an 'x'.
>
Yep. that replaces every digit with an 'x'.
$goodbadnum= preg_replace('!\d!', 'x', $goodbadnum);
Regards,
--
Don Read dread@ispwest.com
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.