optikalefx Posted February 21, 2008 Share Posted February 21, 2008 <?PHP $text = "This is cheese"; $old = 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("z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "m", "l", "k", "j", "i", "h", "g", "f", "e", "d", "c", "b", "a"); echo str_replace($old,$new,$text); ?> im trying to replace each letter with the opposite letter Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 21, 2008 Share Posted February 21, 2008 what is the output? Quote Link to comment Share on other sites More sharing options...
KrisNz Posted February 21, 2008 Share Posted February 21, 2008 I don't think its possible to do it that way, though I can't fully get my head around why, hopefully someone else can explain. Here is another solution. <?php $text = "cheese is a kind of meat, a tasty yellow beef."; $keys = range('a','z'); $final = array_combine($keys,array_reverse($keys)); echo strtr($text,$final); ?> Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 21, 2008 Author Share Posted February 21, 2008 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /hermes/web04/b1609/pow.4ten/htdocs/secret.php on line 2 Fatal error: Call to undefined function  range() in /hermes/web04/b1609/pow.4ten/htdocs/secret.php on line 3 Sorry but i get errors. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 21, 2008 Share Posted February 21, 2008 I don't think its possible to do it that way, though I can't fully get my head around why, hopefully someone else can explain. Here is another solution. <?php $text = "cheese is a kind of meat, a tasty yellow beef."; $keys = range('a','z'); $final = array_combine($keys,array_reverse($keys)); echo strtr($text,$final); ?> works fine for me. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.