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?

Member Avatar for LastMitch

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?

Member Avatar for diafol

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'

commented: Should work :) +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.