fork(1) download
  1. <?php
  2.  
  3. $url = 'localhost/sandbox/hotsite.php?id=14665&open=hot_promocoes&titulo=127121';
  4.  
  5. function setQueryString($url, $key, $val){
  6. $pUrl = parse_url($url);
  7. if(isset($pUrl['query']))
  8. parse_str($pUrl['query'], $pUrl['query']);
  9. else $pUrl['query'] = [];
  10. $pUrl['query'][$key] = $val;
  11.  
  12. $scheme = isset($pUrl['scheme']) ? $pUrl['scheme'].'://' : '';
  13. $host = isset($pUrl['host']) ? $pUrl['host'] : '';
  14. $path = isset($pUrl['path']) ? $pUrl['path'] : '';
  15. $path = count($pUrl['query'])>0 ? $path.'?' : $path;
  16.  
  17. return $scheme . $host . $path . http_build_query($pUrl['query']);
  18. }
  19.  
  20. $u1 = setQueryString($url, 'pg', 1);
  21. $u2 = setQueryString($u1 , 'pg', 2);
  22. $u3 = setQueryString($u2 , 'pg', 3);
  23.  
  24. echo $u1 ."\n" . $u2 . "\n" . $u3;
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
localhost/sandbox/hotsite.php?id=14665&open=hot_promocoes&titulo=127121&pg=1
localhost/sandbox/hotsite.php?id=14665&open=hot_promocoes&titulo=127121&pg=2
localhost/sandbox/hotsite.php?id=14665&open=hot_promocoes&titulo=127121&pg=3