-
September 24th, 2011, 06:27 AM
#1
URL string query
I'm trying to debug a function which decodes URL strings. For example the string file:///C:/some%20filename would get changed to file:///C:/some filename
As expected, the function has replaced "%20" with a space character. For reasons I don't understand though, the function also removes '+' characters from the URL - so file:///C:/some+filename also gets changed to file:///C:/some filename (with the '+' character getting replaced by a space). Would this be normal behaviour for a URL decoder? I didn't think that '+' was special or illegal in any way.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
September 24th, 2011, 08:56 AM
#2
Re: URL string query
hi John
try this function i made
Code:
void STRING_Replace( string &Text, string Key, string Value )
{
// don't allow any infinite loops
if( Value.find( Key ) != string :: npos )
return;
string :: size_type KeyStart = Text.find( Key );
while( KeyStart != string :: npos )
{
Text.replace( KeyStart, Key.size( ), Value );
KeyStart = Text.find( Key );
}
}
best regards
Jacob
-
September 24th, 2011, 11:53 AM
#3
Re: URL string query
Thanks for the suggestion Jacob. To be honest I'm happy enough with the provided code - except for being confused about why it filters out '+' characters and replaces with space characters. I know that certain characters are special in URLs (such as '%') but AFAIK the '+' character is just a normal character, like 'a', 'b' or 'c'. Unless somebody knows different...
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
September 24th, 2011, 12:17 PM
#4
Re: URL string query
The + sign is another way to encode spaces in urls. It is normally used in query strings - you can see this by typing a few words into google and seeing the url it creates for the results page.
If a + sign is actually needed in a url it can be, but must be encoded, as %2B.
-
September 24th, 2011, 12:54 PM
#5
Re: URL string query
Ah, it's making sense now. Thanks Peter.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
September 26th, 2011, 11:51 AM
#6
Re: URL string query
curl_unescape is what you want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|