N
N
NakedFace2015-12-25 22:12:03
PHP
NakedFace, 2015-12-25 22:12:03

How to compare url with string variable?

Hello!
Help solve this issue.
There is a variable to which a part of the url-address is passed. That is, for example, www.site.com/xxxx/. Where xxxx is what is being passed to the variable.
This variable must be compared with the URL of the page the user is on, and depending on this, display a specific message.
At the same time, so that if xxxx/yyyy is passed to the variable, it would display a message specific to yyyy, and not xxxx.

<?$pageurl = $APPLICATION->GetCurPage();?> //получаем урл страницы
<?if (preg_match($pages['PAGE'], $pageurl)):?> // если совпадают, что-то делаем...
....
<?endif;?>

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-12-25
@NakedFace

You can get the last "fragment" from the url. For example like this:

$input = 'xxx/yyy/zzz';
$last_part = substr($input, 1 + strrpos($input, '/')); // zzz

And compare with him.
PS: If you're doing this in a template, then something went wrong, IMHO.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question