homepage Welcome to WebmasterWorld Guest from 54.161.240.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Help with Str replace
BlackRaven




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

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]

 

rainborick




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved