LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cleanest and foolproof way to append query string to URLs (PHP) (https://www.linuxquestions.org/questions/programming-9/cleanest-and-foolproof-way-to-append-query-string-to-urls-php-342075/)

vharishankar 07-11-2005 04:17 AM

Cleanest and foolproof way to append query string to URLs (PHP)
 
What is the best way in PHP to append a query string to a URL? I don't want to merely paste a query string into a text like just appending it.

No assumptions made.

Suppose the URL already contains
Code:

some_file.php?value=0
Then the next query should be
Code:

some_file.php?value=0&next=something
Suppose the URL doesn't contain I want to append
Code:

somefile.php?next=something
Are they any more conditions that I should check for while appending query strings to URLs?

And should this be done using my own custom function or is there an existing PHP function which appends query strings to URLs cleanly?

Hko 07-11-2005 06:15 AM

Quote:

And should this be done using my own custom function or is there an existing PHP function which appends query strings to URLs cleanly?
You might want to have a look at the http_build_query function. It does not support appending directly. But in combination with the parse_url() function it should be fairly easy to implement your own query-string-appending function. I may be better (more efficient) to rewrite your code a little so that http_build_query() is all you need.

vharishankar 07-11-2005 08:32 AM

That's PHP 5. I'm afraid I'm still stuck to PHP 4 (sorry, but my host still has only PHP 4 so I'm forced to create apps in PHP 4.

Is there any equivalent PHP 4 function?

Hko 07-11-2005 10:22 AM

Quote:

Originally posted by Harishankar
That's PHP 5. I'm afraid I'm still stuck to PHP 4 (sorry, but my host still has only PHP 4 so I'm forced to create apps in PHP 4.

Is there any equivalent PHP 4 function?
The parse-url() function is PHP4 however. Try reading the "User Contributed Notes" below that page. There may be a solution there.

vharishankar 07-11-2005 10:38 AM

Ah. I see. Thanks. Somebody has written that function for PHP 4.


All times are GMT -5. The time now is 09:50 PM.