470,833 Members | 1,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Replacing individual characters with preg_replace

I found this code in a PERL script that was written by someone else:

$password =~ tr/a-zA-Z/n-za-mN-ZA-M/;

For example, "newuser1" translates to "arjhfre1" and vice versa. I
realize this isn't the best password encryption, but then I didn't
write the originating software either.

I am trying to convert this to it's PHP equivalent. I understand why
this works in PERL, but I can't figure out the syntax for the
preg_replace command to get it working in PHP. Can someone please
take a crack at it?

Thanks,
Brian
Jul 17 '05 #1
2 1906
["Followup-To:" header set to comp.lang.php.]
Brian Richmond wrote:
I found this code in a PERL script that was written by someone else:

$password =~ tr/a-zA-Z/n-za-mN-ZA-M/;


http://www.php.net/str_rot13

<?php
$password = str_rot13($password);
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
"Brian Richmond" <we*******@4minds.com> wrote in message
news:1e**************************@posting.google.c om...
I found this code in a PERL script that was written by someone else:

$password =~ tr/a-zA-Z/n-za-mN-ZA-M/;

For example, "newuser1" translates to "arjhfre1" and vice versa. I
realize this isn't the best password encryption, but then I didn't
write the originating software either.

I am trying to convert this to it's PHP equivalent. I understand why
this works in PERL, but I can't figure out the syntax for the
preg_replace command to get it working in PHP. Can someone please
take a crack at it?

Thanks,
Brian


The translate command in php is strtr(), it is a one to one translation I
believe.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Sorby | last post: by
2 posts views Thread by matt | last post: by
3 posts views Thread by dornick | last post: by
35 posts views Thread by jacob navia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.