Help? Replace function? Confused...
12-13-2008, 07:33 PM
|
Help? Replace function? Confused...
|
Posts: 78
Name: Ash Kwil
|
Hey, I haven't coded for about 2 years.
Doing a small project that involves making a translator sort of script which will translate text.
E.g I type in "hello" click a button, and the text that comes out is "fummi" you know like replaces the alphabet with different letters e.g h=f e=u l=m o=i
I've been looking on net for ages and have no idea what to use and so far have got nowhere, hopefully some of you can help!
Can anyone find me or write me some examples?
Thanks in advance, Ash! 
|
|
|
|
12-14-2008, 02:39 AM
|
Re: Help? Replace function? Confused...
|
Posts: 20
|
Hello Ash,
I will need to get more clarification before I can help you.
Do you want a translator as in translating languages example: "Hello" - English to "Bonjour" - French? Similar to babel fish?
OR
Do you want a cryptogram? Example: A = Z, B = Y, C = X etc...
So if you typed in "Hello" you would get "Svool"?
Jambla
|
|
|
|
12-14-2008, 08:57 AM
|
Re: Help? Replace function? Confused...
|
Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
|
You might want to take a look at http://us3.php.net/strtr . It pretty much does all the work for you except setup the key you want to use for transformation.
__________________
Jeremy Miller
Please login or register to view this content. Registration is FREE
|
|
|
|
01-03-2009, 09:54 AM
|
Re: Help? Replace function? Confused...
|
Posts: 78
Name: Ash Kwil
|
Yes what I mean is say translating "hello" into "gavvi" some sort if page in which you can type in something and what you typed will be changed, almost like a code language.
Thanks For Your Help So Far
Ash~
|
|
|
|
01-03-2009, 10:52 AM
|
Re: Help? Replace function? Confused...
|
Posts: 10
Name: Tim
|
So like:
HTML Code:
<html>
<head>
<title>Bored Cryptography</title>
</head>
<body>
<form action="encrypt.php" method="post">
Input:<input type="text" name="input" value="<?php echo $_GET['output']; ?>" /><br/>
<input type="submit" value="Encrypt"/>
</form>
</body>
</html>
And in the 'encrypt.php' file:
PHP Code:
<?php $input = $_POST['input'];
$replacementChars = array( "a" => "o", "b" => "p", "c" => "q", "d" => "r", "e" => "s", "f" => "t", "g" => "u", "h" => "v", "i" => "w", "j" => "x", "k" => "y", "l" => "z", "m" => "a", "n" => "b", "o" => "c", "p" => "d", "q" => "e", "r" => "f", "s" => "g", "t" => "h", "u" => "i", "v" => "j", "w" => "k", "x" => "l", "y" => "m", "z" => "n");
$output = strtr($input, $replacementChars);
echo('<script type="text/javascript"> window.location="input.php?output=$output" </script>'); ?>
~Tim
P.S - Sorry if you wanted to do it yourself. Obviously, it's not that hard if I can write it up in 10min inside a quick-reply box :P
Last edited by Crystalmyst; 01-03-2009 at 11:09 AM..
Reason: Forgot semicolon :D
|
|
|
|
01-03-2009, 01:02 PM
|
Re: Help? Replace function? Confused...
|
Posts: 78
Name: Ash Kwil
|
Hey thanks for reply.
The HTML I put in a file called "input.php" and I put the second lot of code in "encrypt.php" but after entering the text I wish to encrypt and clicking "encrypt" I get "$output" in the text box.
I know its most probabley one of my mistakes  Any help is appreciated.
Ash~
|
|
|
|
01-03-2009, 01:58 PM
|
Re: Help? Replace function? Confused...
|
Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
|
it should be
window.location="input.php?output=" . $output
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
|
|
|
|
01-03-2009, 07:49 PM
|
Re: Help? Replace function? Confused...
|
Posts: 78
Name: Ash Kwil
|
PHP Code:
<?php
$input = $_POST['input'];
$replacementChars = array(
"a" => "o",
"b" => "p",
"c" => "q",
"d" => "r",
"e" => "s",
"f" => "t",
"g" => "u",
"h" => "v",
"i" => "w",
"j" => "x",
"k" => "y",
"l" => "z",
"m" => "a",
"n" => "b",
"o" => "c",
"p" => "d",
"q" => "e",
"r" => "f",
"s" => "g",
"t" => "h",
"u" => "i",
"v" => "j",
"w" => "k",
"x" => "l",
"y" => "m",
"z" => "n");
$output = strtr($input, $replacementChars);
echo('<script type="text/javascript">
window.location="input.php?output=" . $output"
</script>');
?>
This is the current code. Now the page simply stays on encrypt.php and I am left with a blank white screen.
Thanks for your help so far.
Ash~
|
|
|
|
01-03-2009, 08:10 PM
|
Re: Help? Replace function? Confused...
|
Posts: 744
Name: Mattias Nordahl
Location: Sweden
|
I believe it should be like this.
PHP Code:
echo('<script type="text/javascript"> window.location="input.php?output=' . $output . '"</script>');
Although, why use javascript to redirect? You could simply do this.
PHP Code:
header("Location: input.php?output=$output");
Last edited by lizciz; 01-03-2009 at 08:11 PM..
|
|
|
|
01-03-2009, 08:33 PM
|
Re: Help? Replace function? Confused...
|
Posts: 78
Name: Ash Kwil
|
Thanks A Lot Everyone, It Works Perfect =)
Ash~
|
|
|
|
01-05-2009, 02:19 AM
|
Re: Help? Replace function? Confused...
|
Posts: 10
Name: Tim
|
'cos you can't add header changes unless you're buffering the page, no?
And I'm using AJAX for all my sites, so Javascript was the best idea.
You shouldn't have to stick it out of the string for it to work, PHP should still parse the variable within the string, no?
~Tim
|
|
|
|
|
« Reply to Help? Replace function? Confused...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|