3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array('foo'=>'bar', 'baz'=>'boom', 'cow'=>'milk', 'php'=>'hypertext processor'); echo uri_appendQuery('http://domena/cesta/subor?query-string', $data), PHP_EOL; echo uri_appendQuery('http://domena/cesta/?query-string', $data), PHP_EOL; echo uri_appendQuery('http://domena/cesta/subor?', $data), PHP_EOL; echo uri_appendQuery('http://domena/cesta/subor', $data), PHP_EOL; echo uri_appendQuery('http://domena/cesta/subor?query-string', $data, TRUE), PHP_EOL; /** * Doplní k URL adrese zadané parametre za otáznikom. * * @param string URL adresa * @param array [názov parametru => hodnota] * @param bool ak je TRUE, nahradia sa všetky & v adrese za &amp; * @return string patrične upravenú URL adresu */ function uri_appendQuery($uri, array $args, $html = FALSE) { if(!$args) { // $args môže byť prázdne pole return $uri; } $sep= $html ? '&amp;' : '&'; if(FALSE === $qmpos = strpos($uri, '?')) { // adresa ešte neobsahuje query string $uri .= '?'; } elseif(strlen($uri) !== ($qmpos + 1)) { // adresa už obsahuje query string $uri .= $sep; } return $uri . http_build_query($args, NULL, $sep); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /in/Srngt on line 36 http://domena/cesta/subor?query-string&foo=bar&baz=boom&cow=milk&php=hypertext+processor Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /in/Srngt on line 36 http://domena/cesta/?query-string&foo=bar&baz=boom&cow=milk&php=hypertext+processor Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /in/Srngt on line 36 http://domena/cesta/subor?foo=bar&baz=boom&cow=milk&php=hypertext+processor Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /in/Srngt on line 36 http://domena/cesta/subor?foo=bar&baz=boom&cow=milk&php=hypertext+processor Deprecated: http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated in /in/Srngt on line 36 http://domena/cesta/subor?query-string&amp;foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
Output for 5.1.2 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
http://domena/cesta/subor?query-string&foo=bar&baz=boom&cow=milk&php=hypertext+processor http://domena/cesta/?query-string&foo=bar&baz=boom&cow=milk&php=hypertext+processor http://domena/cesta/subor?foo=bar&baz=boom&cow=milk&php=hypertext+processor http://domena/cesta/subor?foo=bar&baz=boom&cow=milk&php=hypertext+processor http://domena/cesta/subor?query-string&amp;foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
Output for 5.1.0 - 5.1.1
Warning: http_build_query() expects at most 2 parameters, 3 given in /in/Srngt on line 36 http://domena/cesta/subor?query-string& Warning: http_build_query() expects at most 2 parameters, 3 given in /in/Srngt on line 36 http://domena/cesta/?query-string& Warning: http_build_query() expects at most 2 parameters, 3 given in /in/Srngt on line 36 http://domena/cesta/subor? Warning: http_build_query() expects at most 2 parameters, 3 given in /in/Srngt on line 36 http://domena/cesta/subor? Warning: http_build_query() expects at most 2 parameters, 3 given in /in/Srngt on line 36 http://domena/cesta/subor?query-string&amp;
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/Srngt on line 22
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting '&' or T_VARIABLE or T_CONST in /in/Srngt on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE or T_CONST in /in/Srngt on line 22
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'&'' or `T_VARIABLE' or `T_CONST' in /in/Srngt on line 22
Process exited with code 255.

preferences:
265.69 ms | 401 KiB | 326 Q