473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to use comma in URLs

It's possible to use comma's in URLs for example: ?page=$page&id=120

Instead of AND (&) we use comma

?page=$page,id=120
Oct 4 '10 #1
6 6478
Atli
5,058 Expert 4TB
That should work fine. A comma is not a special char in URLs so it should come through as a part of the "page" value.
Oct 5 '10 #2
Can you give me an example for this to replace & (and) with , (comma)
Oct 5 '10 #3
Dormilich
8,658 Expert Mod 8TB
as far as I know, this needs your server to rewrite the url containing commas back into ampersands. in contrast to & (parameter separator), the comma does not have a special meaning. otherwise you’ll only get one URL parameter (page).
Oct 5 '10 #4
kovik
1,044 Expert 1GB
Or, you could convert it in PHP.

Expand|Select|Wrap|Line Numbers
  1. if (!empty($_GET) && count($_GET) == 1) {
  2.     $query_vars = array();
  3.     $query_data = explode(',', current($_GET));
  4.  
  5.     if (!empty($query_data)) {
  6.         $query_vars[key($_GET)] = array_shift($query_data);
  7.  
  8.         foreach ($query_data as $query_pair) {
  9.             if (!empty($query_pair)) {
  10.                 $query_pair = explode('=', $query_pair, 2);
  11.  
  12.                 if (count($query_pair) == 1) {
  13.                     $query_vars[$query_pair[0]] = null;
  14.                 } else {
  15.                     $query_vars[$query_pair[0]] = $query_pair[1];
  16.                 }
  17.             }
  18.         }
  19.     }
  20.  
  21.     $_GET = $query_vars;
  22. }
Untested.
Oct 5 '10 #5
kovik
1,044 Expert 1GB
I found this idea interesting, and decided to write something a bit more concrete to solve your problem. I've explained it in more detail here.

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Rebuild the superglobal $_GET array
  3.  *
  4.  * @param string $query_string The query string
  5.  * @param string $ampersand The replacement for ampersands in the query string
  6.  * @param string $equality The replacement for equality signs in the query string
  7.  * @return void
  8.  */
  9. function rebuild_get($query_string, $ampersand = '&', $equality = '=') {
  10.     if (!empty($query_string)) {
  11.         // Empty the $_GET array
  12.         $_GET = array();
  13.  
  14.         // Insert key => value pairs into the $_GET array
  15.         foreach (explode($ampersand, $query_string) as $pair) {
  16.             $pair_data = explode($equality, $pair, 2);
  17.             $_GET[$pair_data[0]] = (count($pair_data) > 1) ? $pair_data[1] : null;
  18.         }
  19.     }
  20. }
Oct 8 '10 #6
Markus
6,050 Expert 4TB
Why do you want to use a comma instead of an ampersand? AFAIK, the valid separators are ampersands (&) and semi-colons (;).
Oct 8 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Howard Brazee | last post by:
I would like to click on a URL of a html document that will open several URLs at once for me. Does someone have an example of a html document that will do this?
1
by: DM | last post by:
I'm working on a site with more than 1700 HTML files. We'll be moving files around on this site a lot because we're reorganizing it. I'm thinking of writing a script that will convert all URLs in...
7
by: AES | last post by:
Encountered a URL containing a comma the other day -- the first time I've ever noticed that, so far as I can recall. It worked fine, however, and I gather commas are legal in URLs. Out of...
11
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
9
by: Wayne | last post by:
I have the following string: "smith", "Joe", "West Palm Beach, Fl." I need to split this string based on the commas, but as you see the city state contains a comma. String.split will spilt the...
15
by: Lighter | last post by:
In 5.3.3.4 of the standard, the standard provides that "The lvalue-to- rvalue(4.1), array-to-pointer(4.2),and function-to-pointer(4.3) standard conversions are not applied to the operand of...
3
by: WebCM | last post by:
How to apply nice URL-s into CMS? 1. Should we use nice urls for every page? 2. Do we need to put a FULL path into <a href="">? 3. What is faster and better? a) 10 rules in .htaccess...
7
by: Hermann | last post by:
I run a server with apache 1.3 and php 5. Yesterday I notice that sometimes the HTTP_HOST server variable has a comma separated list in it. Let's say my domain name is: www.mydomain.com Usually...
0
by: kshw | last post by:
Hi, I’m new to programming. I’m currently learning python to write a web crawler to extract all text from a web page, in addition to, crawling to further URLs and collecting the text there. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.