473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1997
["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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.