Jump to content

Recommended Posts

I was working on a translator that uses 2 arrays and a str_replace

But for some reason, 2 letters don't output as the should

 

Ex.

If I type in chris, I get cChrize_ instead of cChriz_

 

Here are the arrays:

$orig = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
$new = array('aa', 'b', 'cC', 'de', 'E', 'f', 'gj', 'h', 'i', 'j', 'k', 'll', 'm', 'n', 'oo', 'pe', 'qu', 'r', 'z_', 'te', 'u', 've', 'wu', 'x', 'y', 'ze');

 

Whats wrong?

 

 

I don't know how your translation code looks but this works

$orig 	 = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
$new 	 = array('aa', 'b', 'cC', 'de', 'E', 'f', 'gj', 'h', 'i', 'j', 'k', 'll', 'm', 'n', 'oo', 'pe', 'qu', 'r', 'z_', 'te', 'u', 've', 'wu', 'x', 'y', 'ze');
$string  = "chris";

$keys = array();
for($x = 0; $x < strlen($string); $x++) {
$key = array_search(substr($string,$x,1), $orig);
$keys[] = $key;
}

foreach($keys as $key) {
$newString .= $new[$key];
}

print $newString;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.