Sebastian Botez Sebastian Botez - 2 months ago 7x
PHP Question

Regex. Find in string any PHP GET variables

Hello I'm trying to create a Regex that can find any GET variables from strings.
For example:

My function shoud return true.

Function shoud return false.

The pattern shoud find


Any ideas? Thanks very much!


I suggests to take a look at parse_url function of php.

It breaks a url into components like path and query, so can check if a query exists in your uri or not, to get the path of uri etc.

In your example:

$uri = '';
parse_url($uri, $parts);
echo $parts['query']; #title=test
echo $parts['path']; #'question/ask

if (isset($parts['query']) {
    return true;