0

My url's are similar like this:

website/search/category,Room/region,Oregon/
website/search/category,Room/
website/search/category,Room/city,Palm Bay/
website/search/city,Palm Bay/
website/search/region,Florida/

It always contains single or combination of CATEGORY CITY REGION

I want to echo in an if statement, for example:
if url contains "category,xxx" then echo "category is xxx".
(xxx can be anything)

I found this code:

                <?php $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
                if (false !== strpos($url,'Room')) {
                    echo 'Room';
                } 
                    echo 'No Room';
                } ?>

But this method is large when I have 12 or more category words, 50 region names, and hundreds of city words to compare. How to make this more easy?

3
Contributors
2
Replies
17
Views
4 Years
Discussion Span
Last Post by diafol
0

But this method is large when I have 12 or more category words, 50 region names, and hundreds of city words to compare. How to make this more easy?

Is this in an array or from your database?

Have you thought about using htaccess/Remod?

Edited by LastMitch

1

You can use parse_url() to get the 'bits' and use the 'path' item. Just search in that.
Explode on '/' to isolate the city, region etc.
Then explode on ',' to get the 'key' and 'value'

Votes + Comments
Should work :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.