3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Everything you enter here will be executed by our servers. Try it! $uri = "http://fashion/ru/items/2?sort%5B%5D=1&str%5B%5D=4&curs%5B%5D=1&page=2&page=1&page=2&page=5&page=4&page=3&page=2&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&tesdsd=2"; function sgp($url, $varname, $value) // substitute get parameter { if (is_array($varname)) { foreach ($varname as $i => $n) { $v = (is_array($value)) ? ( isset($value[$i]) ? $value[$i] : NULL ) : $value; $url = sgp($url, $n, $v); } return $url; } preg_match('/^([^?]+)(\?.*?)?(#.*)?$/', $url, $matches); $gp = (isset($matches[2])) ? $matches[2] : ''; // GET-parameters if (!$gp) return $url; $pattern = "/([?&])$varname=.*?(?=&|#|\z)/"; if (preg_match($pattern, $gp)) { $substitution = ($value !== '') ? "\${1}$varname=" . preg_quote($value) : ''; $newgp = preg_replace($pattern, $substitution, $gp); // new GET-parameters $newgp = preg_replace('/^&/', '?', $newgp); } else { $s = ($gp) ? '&' : '?'; $newgp = $gp.$s.$varname.'='.$value; } $anchor = (isset($matches[3])) ? $matches[3] : ''; $newurl = $matches[1].$newgp.$anchor; return $newurl; } var_dump(sgp($uri));
Output for 7.1.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function sgp(), 1 passed in /in/8DmJp on line 37 and exactly 3 expected in /in/8DmJp:5 Stack trace: #0 /in/8DmJp(37): sgp('http://fashion/...') #1 {main} thrown in /in/8DmJp on line 5
Process exited with code 255.
Output for 5.1.0 - 5.6.28, 7.0.0 - 7.0.14
Warning: Missing argument 2 for sgp(), called in /in/8DmJp on line 37 and defined in /in/8DmJp on line 5 Warning: Missing argument 3 for sgp(), called in /in/8DmJp on line 37 and defined in /in/8DmJp on line 5 Notice: Undefined variable: varname in /in/8DmJp on line 7 Notice: Undefined variable: varname in /in/8DmJp on line 21 Notice: Undefined variable: varname in /in/8DmJp on line 29 Notice: Undefined variable: value in /in/8DmJp on line 29 string(200) "http://fashion/ru/items/2?sort%5B%5D=1&str%5B%5D=4&curs%5B%5D=1&page=2&page=1&page=2&page=5&page=4&page=3&page=2&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&tesdsd=2&="
Output for hhvm-3.10.0 - 3.12.0
Warning: sgp() expects exactly 3 parameters, 1 given in /in/8DmJp on line 7 Notice: Undefined variable: varname in /in/8DmJp on line 7 Notice: Undefined variable: varname in /in/8DmJp on line 21 Notice: Undefined variable: varname in /in/8DmJp on line 29 Notice: Undefined variable: value in /in/8DmJp on line 29 string(200) "http://fashion/ru/items/2?sort%5B%5D=1&str%5B%5D=4&curs%5B%5D=1&page=2&page=1&page=2&page=5&page=4&page=3&page=2&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&tesdsd=2&="
Output for 4.3.0 - 5.0.5
Warning: Missing argument 2 for sgp() in /in/8DmJp on line 5 Warning: Missing argument 3 for sgp() in /in/8DmJp on line 5 string(200) "http://fashion/ru/items/2?sort%5B%5D=1&str%5B%5D=4&curs%5B%5D=1&page=2&page=1&page=2&page=5&page=4&page=3&page=2&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&page=1&tesdsd=2&="