Re: Regular expressions
| From: | CC Zona | Date: | Wed, 18 Jul 2001 07:33:08 +0000 |
| Subject: | Re: Regular expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-58402@lists.php.net to get a copy of this message | ||
In article <000b01c10f4a$d569c5c0$0300a8c0@sparlak>,
me@philth.net.nz (Philip Murray) wrote:
> In Perl you can do this:
>
> $foo =~ tr/012/mpf/;
>
> Which is the same as:
>
> $foo = str_replace("0", "m", $foo);
> $foo = str_replace("1", "p", $foo);
> $foo = str_replace("2", "f", $foo);
>
> in PHP.
>
> Is there a more elegant way of doing this in PHP?
See the docs on str_replace() or preg_replace, both of which can take
arrays as arguments, or on strtr() which appears to be the most direct
equivalent to your Perl expression.
--
CC