Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help? Replace function? Confused...
Old 12-13-2008, 07:33 PM Help? Replace function? Confused...
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
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!
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
 
Register now for full access!
Old 12-14-2008, 02:39 AM Re: Help? Replace function? Confused...
jambla's Avatar
Average Talker

Posts: 20
Trades: 0
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
jambla is offline
Reply With Quote
View Public Profile
 
Old 12-14-2008, 08:57 AM Re: Help? Replace function? Confused...
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 01-03-2009, 09:54 AM Re: Help? Replace function? Confused...
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
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~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
Old 01-03-2009, 10:52 AM Re: Help? Replace function? Confused...
Novice Talker

Posts: 10
Name: Tim
Trades: 0
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
Crystalmyst is offline
Reply With Quote
View Public Profile
 
Old 01-03-2009, 01:02 PM Re: Help? Replace function? Confused...
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
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~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
Old 01-03-2009, 01:58 PM Re: Help? Replace function? Confused...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-03-2009, 07:49 PM Re: Help? Replace function? Confused...
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
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~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
Old 01-03-2009, 08:10 PM Re: Help? Replace function? Confused...
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
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..
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 01-03-2009, 08:33 PM Re: Help? Replace function? Confused...
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
Thanks A Lot Everyone, It Works Perfect =)

Ash~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
Old 01-05-2009, 02:19 AM Re: Help? Replace function? Confused...
Novice Talker

Posts: 10
Name: Tim
Trades: 0
'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
Crystalmyst is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help? Replace function? Confused...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33977 seconds with 12 queries