V
V
vimbatu2021-08-12 11:34:17
PHP
vimbatu, 2021-08-12 11:34:17

How to replace numbers in the $GET parameter string with a regular expression?

Greetings.

Tell me how in the condition line:

if (isset($_GET['PAGEN_1']) && intval($_GET['PAGEN_1'])>0) {

replace the number 1 in PAGEN_1 with any integer so that the condition is fulfilled.
I do not quite understand how to correctly write a regular expression in such a construction.

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2021-08-12
@SagePtr

Something like this:

foreach ($_GET as $key => $value) {
  if (preg_match('/^PAGEN_(\d+)$/', $key, $matches)) {
    // пользователь передал параметр $_GET[$key] со значением $value, номер сохранён в $matches[1]
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question