A
A
AndTheEnd2018-08-06 13:50:26
PHP
AndTheEnd, 2018-08-06 13:50:26

How to include characters in a regular expression after a get request?

Hello. Such a question
There is a url: site.ru
And there are additions like:
/test/n-nr/ (site.ru/test/n-nr/)
and
/test/ (site.ru/test/)
and
/test/?dn7674 (site.ru/test/?dn7674 )
Exclude the URL in which /n-nr/ goes after test but leave the URL /test/?dn7674
Now I have
$url = $_SERVER["REQUEST_URI"];
$preg = preg_match("/\/test\/./", $url);
How can I leave ?dn7674
It doesn't work
$url = $_SERVER["REQUEST_URI"];
$preg = preg_match("/\/test\/.(^[?/.])/", $url);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick Sdk, 2018-08-06
@lidacriss

Why do you need regulars at all?
you have php )
php.net/manual/ru/function.parse-url.php

$url = $_SERVER['REQUEST_URI'] ?? '';
$parse_url = parse_url($url);
if ($parse_url && $parse_url['path'] == 'test') {
    // some code
    print_r($parse_url['query']);
}

well, you can see the incoming get parameters somewhere like this:
$_GET
$_REQUEST
// и тд

php.net/manual/ru/reserved.variables.get.php
php.net/manual/ru/reserved.variables.request.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question