472,950 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

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 1983
["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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sorby | last post by:
Hi I've been coding in PHP for a little while now and was starting to feel pretty confident but then realise I need to understand regular expressions to solve a particular problem I've got ......
2
by: matt | last post by:
I have an upload script for a photo and a caption. It all goes pear shaped when I upload a character like ' " or / \ | Is there anyway I can parse through the filename when submitting the form and...
3
by: dornick | last post by:
So I want to do the above, and I really, REALLY don't want to rewrite the entire file. I've been working on it for a while now, and can't for the life of me get it functioning. Basically, I want...
35
by: jacob navia | last post by:
Hi guys! I like C because is fun. So, I wrote this function for the lcc-win32 standard library: strrepl. I thought that with so many "C heads" around, maybe we could improve it in a...
25
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found...
2
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP...
3
by: zainally | last post by:
I want to detect uppercase characters in a string and separate the two words in it by a space. I know I can use preg_replace for it, but I am not very good at regular expressions. Can someone help?...
2
by: nobugus | last post by:
Hello, This might be more of a PHP-thing than REGEX, but here's my problem: I am using a HEX value to find and replace 'white spaces' with 'x': take this example: $string = preg_replace('//u',...
2
by: Big Moxy | last post by:
I want to send html formatted text yet strip out special characters (e.g. quotes and semi colons). I've seen preg_replace examples like $messageout = preg_replace('/\(\)<>]/i','',$message); to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.