?
Solved

Making simple converter with php

Posted on 2008-02-08
8
Medium Priority
?
173 Views
Last Modified: 2013-12-12
I want to make a php script that would read what a person submitted in a form and change stuff to what I set, such as a converter/encrypter/etc.

Example:

The Form -
Text to Convert:

I fill it in as -
Text to Convert: convert this

After being submitted, the php script would change "convert" to "FFconvert" and "this" to "FFthis" .

Basically, I want it like this for example:

$u65 = "A";
$c65 = "chr(65);";

If it finds $u65 (aka the letter A) in the formdata, it would change it to $c65 (aka chr(65);)and output that.

It's basically like a converter except I set what to convert to what.
0
Comment
Question by:HiTechFail
  • 4
  • 3
8 Comments
 
LVL 19

Expert Comment

by:Michael701
ID: 20856358
see php manual for

string strtr ( string str, string from, string to )

This function returns a copy of str, translating all occurrences of each character in from to the corresponding character in to and returning the result.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 20856885
HiTechFail, it's not clear from your two differing examples what your goal is.  Please explain further.
0
 
LVL 2

Author Comment

by:HiTechFail
ID: 20857697
Michael, would that work for multiple characters?

And let me make an example code (TOTALLY MADE UP - NOT REAL PHP):

They fill in the form on my site, after that, I want a php script to change each letter they typed (Normal text) to something I choose.

$t1 = "A"; THIS WOULD BE CHANGED TO $b1 = "gA";
$t2 = "B"; THIS WOULD BE CHANGED TO $b2 = "kB";
$t3 = "C"; (and so on, whole alphabet)

Therefore, if I submitted "ab", it would convert it to "gAkB"
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 19

Expert Comment

by:Michael701
ID: 20857904
are you always adding just one character to every character they type?
0
 
LVL 2

Author Comment

by:HiTechFail
ID: 20857910
Nono, only an example.

What I'm trying to do is convert text to it's chr(); equivalent.

Such as, the capital letter A would be chr(65);

Trying to make a converter to convert regular text into chr()'s
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 2000 total points
ID: 20857952
something as simple as this?
$input='ABCDEFGHIJ';
$output=''
for ($i=0; $i<strlen($input); $i++ )
  $output.='chr('.(int) ord($input[$i])."');";
 
echo $output;

Open in new window

0
 
LVL 2

Author Comment

by:HiTechFail
ID: 20858114
Yes that looks like it would work, and I would be able to make $input collect what was submitted in the POST form?
0
 
LVL 2

Author Comment

by:HiTechFail
ID: 20859993
Worked.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question