Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if parameters exist in an URL

How can I check if an URL has parameters in it?

for instance, if the string is like this,

form_page_add.php?parent_id=1

return true

But if it is like this,

form_page_add.php?

return nothing

Thanks.

EDIT:

Sorry for not being clear, the URL is submitted from a from as a string. and I will store that string in a variable,

if(isset($_POST['cfg_path'])) $cfg_path = trim($_POST['cfg_path']);

so I need to check this variable $cfg_path whether is has parameters in it.

like image 717
Run Avatar asked Nov 26 '22 22:11

Run


1 Answers

Could also look for a specific key with array_key_exists(), e.g.

if(array_key_exists('some-key', $_GET))

http://php.net/manual/en/function.array-key-exists.php

like image 132
barfoon Avatar answered Dec 12 '22 01:12

barfoon