Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help with Str replace

     
6:04 am on Dec 15, 2010 (gmt 0)

10+ Year Member



Hi,
i have the following 2 arrays that i am looking to replace variables from. However my problem is how to tell to not replace variables that are in %XX format. Right now 0 will get replaced with %30, and this will then again get replaced with %%330 (replaced 3 with %33). Any help greatly appreciated. Thanks


$URL_Chars=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','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','0','1','2',
'3','4','5','6','7','8','9','-','.','_','~',':','/','?','#','[',']','@','!','$',
'&','\'','(',')','*','+',',',';','=','%'
);

$URL_Encoded_Chars=array(
'%41','%42','%43','%44','%45','%46','%47','%48','%49',
'%4A','%4B','%4C','%4D','%4E','%4F','%50','%51','%52','%53','%54','%55','%56',
'%57','%58','%59','%5A','%61','%62','%63','%64','%65','%66','%67','%68','%69',
'%6A','%6B','%6C','%6D','%6E','%6F','%70','%71','%72','%73','%74','%75','%76','%77',
'%78','%79','%7A','%30','%31','%32','%33','%34','%35','%36','%37','%38','%39',
'%2D','%2E','%5F','%7E','%3A','%2F','%3F','%23','%5B','%5D','%40','%21','%24',
'%26','%27','%28','%29','%2A','%2B','%2C','%3B','%3D','%25'
);

$Hex_URL=str_replace($URL_Chars,$URL_Encoded_Chars,$Hex_URL);

[edited by: coopster at 2:03 pm (utc) on Dec 15, 2010]
[edit reason] fixed sidescroll [/edit]

3:47 pm on Dec 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My advice would be to simply create a function that will translate the data variables one at a time, rather than trying to create an elegant one-line wonder.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month