I would like to regex a query string which is contained in a href attribute of a tag. My aim is to get, for example, the page number of this a tag:
<a class="page-numbers" href="/website/admin/back.php?page=my_page&pagenum=2&id=12">next</a>
I would like to get the query pagenum
. Is there a way to directly get it with a regex or someting like this?
Here my code:
$page_link = '<a class="page-numbers" href="/website/admin/back.php?page=my_page&pagenum=3&id=12">next</a>';
$page_nb = preg_match('/<a href="(.+)">/', $page_link, $matches);
$page_nb = (isset($matches[1])) ? $matches[1] : $page_nb;
$page_nb = parse_str(parse_url($page_nb, PHP_URL_QUERY), $params);
$page_nb = $params['pagenum'];
EDIT: I need this number because I will use it for a query. The page number text not necessarily corresponds to the query page number. And the pagination can be a little bit complex. I just need to retrieve this information for some stuff not relating on clicking on the button.