[ create a new paste ] login | about

Link: http://codepad.org/fhDVAMfF    [ raw code | output | fork ]

PHP, pasted on Oct 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    <?php
    
    $urls = array(
             'http://www.example.com',
             'http://www.example.com/a/',
             'http://www.example.com/a/?q1=one',
             'http://www.example.com/a.html',
             'http://www.example.com/a.html?q1=one'
            );
    
    $query = 'q2=two';
    
    foreach($urls as &$url) {
       $separator = (parse_url($url, PHP_URL_QUERY) == NULL) ? '?' : '&';
        
       $url .= $separator . $query;
      
    }
    
    var_dump($urls);


Output:
1
2
3
4
5
6
7
8
9
10
11
12
    array(5) {
  [0]=>
  string(29) "http://www.example.com?q2=two"
  [1]=>
  string(32) "http://www.example.com/a/?q2=two"
  [2]=>
  string(39) "http://www.example.com/a/?q1=one&q2=two"
  [3]=>
  string(36) "http://www.example.com/a.html?q2=two"
  [4]=>
  &string(43) "http://www.example.com/a.html?q1=one&q2=two"
}


Create a new paste based on this one


Comments: