Hi,
I've got a php script that receives parts of URLs from another script and
transforms it to be HTTP compliant.
For example, if I receive a parameter like "dir=some directory/" I have to
convert it to "dir=some%20directory/".
I make this with this 2 lines of code:
$str = explode(" ",$_GET["dir"]);
fputs($fp,"GET /share/" . implode("%20",$str) . " HTTP/1.0\r\n");
Everything was working fine, until I have created a directory called "C++".
I don't know why but the code above convert it to "C ".
It should keep it unchanged, because what the code do is searching for SPACE
characters ' ' only and change it to "%20". I was not expecting that it
would change '+' characters.
What is wrong with the code?
Thanks in advance,
Nuno Paquete 9 2002
Nuno Paquete wrote: Hi,
I've got a php script that receives parts of URLs from another script and transforms it to be HTTP compliant. For example, if I receive a parameter like "dir=some directory/" I have to convert it to "dir=some%20directory/". I make this with this 2 lines of code:
$str = explode(" ",$_GET["dir"]); fputs($fp,"GET /share/" . implode("%20",$str) . " HTTP/1.0\r\n");
You're killing flies with a shotgun. What you really need is http://www.php.net/manual/en/function.urlencode.php
Berislav
--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
*** Nuno Paquete wrote/escribió (Fri, 20 Aug 2004 11:53:01 +0100): For example, if I receive a parameter like "dir=some directory/" I have to convert it to "dir=some%20directory/".
Two options:
echo urlencode('dir=some directory/'); // prints 'dir=some+directory/'
echo rawurlencode('dir=some directory/'); // prints 'dir=some%20directory/'
I'm unsure though about what standards say about encoding spaces in URLs
(i.e, which is better, "+" or "%20"?)
--
-- Álvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
Alvaro G Vicario wrote:
[ ... ] echo urlencode('dir=some directory/'); // prints 'dir=some+directory/' echo rawurlencode('dir=some directory/'); // prints 'dir=some%20directory/'
But remember that equals signs and solidi are percent-
encoded too. Your examples output 'dir%3Dsome+directory%2F'
and 'dir%3Dsome%20directory%2F' respectively.
I'm unsure though about what standards say about encoding spaces in URLs (i.e, which is better, "+" or "%20"?)
I had misunderstood this, but it was explained to me a while
ago. Hopefully now I have it right. ;o)
The plus sign is reserved in query components, which means
the semantics of the URI change if it's replaced by its
percent-encoding. How it's interpreted is up to the program
handling it. The URI standard doesn't assign any meaning to
plus signs; whereas %20 always means a US-ASCII space.
HAGW Álvaro!
--
Jock
Alvaro G Vicario wrote: *** Nuno Paquete wrote/escribió (Fri, 20 Aug 2004 11:53:01 +0100): For example, if I receive a parameter like "dir=some directory/" I have to convert it to "dir=some%20directory/".
Two options:
echo urlencode('dir=some directory/'); // prints 'dir=some+directory/' echo rawurlencode('dir=some directory/'); // prints 'dir=some%20directory/'
I'm unsure though about what standards say about encoding spaces in URLs (i.e, which is better, "+" or "%20"?)
Hi.
The functions you described both encode everything, including slashs (/),
changing it for %2F. I want to keep '/' unchanged.
What I think that is strange is that I want to manipulate a string that was
supposed to be already encoded, because when the script is asked from
another page, it is accessed from a link like this: "script.php?dir=some
20directory" but then, inside script.php $_GET["dir"] becomes "some
directory". Why?
So, I need to encode it again (understandable), but I don't want to enconde
'/' characters.
Any suggestions?
Regards.
Nuno Paquete wrote:
[ ... ] What I think that is strange is that I want to manipulate a string that was supposed to be already encoded, because when the script is asked from another page, it is accessed from a link like this: "script.php?dir=some 20directory" but then, inside script.php $_GET["dir"] becomes "some directory". Why?
Because %20 means a space; %20 is the percent-encoding of a
US-ASCII space character; see RFC2396 sec. 2.4. If you
intended $_GET['dir'] to be 'some%20directory', the percent
sign must itself be percent-encoded as %25, giving a query
component of 'dir=some%2520directory'.
So, I need to encode it again (understandable), but I don't want to enconde '/' characters.
Any suggestions?
How did you do it before?
--
Jock
> How did you do it before?
I get the result of the web server. This is a script that deals with HTTP
connections. I establish the connection, I "speak" HTTP with the server
(GET /dir/ HTTP/1.0) and receive the directory content (Index Directory).
Then I manipulate the result, and this result already contains the url
encoded.
But now I need to POST the (already encoded) url and strangely I cant get
the encoded result on the other side. It seems that it is decoded in the
middle, because "some%20directory" becomes "some directory".
Any suggestions?
Thanks again.
Nuno Paquete wrote: How did you do it before?
I get the result of the web server. This is a script that deals with HTTP connections. I establish the connection, I "speak" HTTP with the server (GET /dir/ HTTP/1.0) and receive the directory content (Index Directory). Then I manipulate the result, and this result already contains the url encoded. But now I need to POST the (already encoded) url and strangely I cant get the encoded result on the other side. It seems that it is decoded in the middle, because "some%20directory" becomes "some directory". Any suggestions?
Thanks again.
It's done.
Instead of make links with GET method, I did make a form and then used POST
method.
It's working perfectly, and I don't need to use urlencode() function.
Best regards,
Nuno Paquete
*** Nuno Paquete wrote/escribió (Sat, 21 Aug 2004 14:18:45 +0100): The functions you described both encode everything, including slashs (/), changing it for %2F. I want to keep '/' unchanged.
If the slash is part of the parameter you must encode it.
Also, as John said, it also encodes the equal size, which should be left
outside the function call.
--
-- Álvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--
*** Alvaro G Vicario wrote/escribió (Mon, 23 Aug 2004 08:19:59 +0200): Also, as John said, it also encodes the equal size
sign, not size. Sorry for the typos...
--
-- Álvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dim |
last post by:
I found that C# has some buggy ways to process string across methods.
I have a class with on global string var and a method where i add / remove
from this string
Consider it a buffer... with some...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: zoro |
last post by:
Hi,
I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party
string handling library that includes some very useful string
functions, in particular I'm interested in BEFORE (return...
|
by: WaterWalk |
last post by:
Hello, I'm currently learning string manipulation. I'm curious about
what is the favored way for string manipulation in C, expecially when
strings contain non-ASCII characters. For example, if...
|
by: micklee74 |
last post by:
hi
if i have a some lines like this
a ) "here is first string"
b ) "here is string2"
c ) "here is string3"
When i specify i only want to print the lines that contains "string" ie
the first...
|
by: Niyazi |
last post by:
Hi,
Does anyone knows any good code for string manipulation similar to
RegularExpresion?
I might get a value as string in a different format. Example:
20/02/2006 or 20,02,2006 or ...
|
by: crprajan |
last post by:
String Manipulation: Given a string like “This is a string”, I want to remove all single characters( alphabets and numerals) like (a, b, 1, 2, .. ) .
So the output of the string will be “This is...
|
by: Frinavale |
last post by:
I currently have a .NET application that has an object which passes a string (a connection string) as a parameter to another object that does database manipulation.
This string isn't stored...
|
by: frankeljw |
last post by:
I have 2 Java strings
1st String is a series of names, colons, and numbers
ie) Name1:13:Name2:4526:Name3:789:Name4:3729:Name5:6:Name6:44
2nd String is a name
ie) Name2
I need to get the...
|
by: mann_mathann |
last post by:
can anyone tell me a solution:
i cannot use the features in standard c++ string classgh i included
the string.h file but still its not working.
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |