LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-11-2005, 04:17 AM   #1
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
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?
 
Old 07-11-2005, 06:15 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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.
 
Old 07-11-2005, 08:32 AM   #3
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
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?
 
Old 07-11-2005, 10:22 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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.
 
Old 07-11-2005, 10:38 AM   #5
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178

Original Poster
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Ah. I see. Thanks. Somebody has written that function for PHP 4.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 09:28 AM
Perl/regexp help... - query string parsing... lowpro2k3 Programming 4 05-11-2005 05:18 PM
mysql query for multibyte string onnyloh Programming 3 12-03-2004 08:29 PM
Send query string via MIRC script cadj Programming 0 08-25-2004 06:25 AM
PHP random additions to query string Riley Programming 2 07-09-2003 02:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration