Friday , December 20 2024

If the link contains the word

The case:
If a word occurs in the URL, then you need to display some text. For example, if the URL contains “hahaha”, then on the page you need to display the text “description of the text hahaha”.

PHP solution:

<?php
if(strpos($_SERVER['REQUEST_URI'], 'hahaha') !== false){
            echo "description of the text hahaha";
        }
?>

Instead of hahaha write your part of the URL, and instead of description of the text hahaha write your text.

The 2nd version (in general, everything is the same, with an additional else if):

<?php if(strpos($_SERVER['REQUEST_URI'], 'hahaha') !== false):?>
    description of the text hahaha
<?php elseif(strpos($_SERVER['REQUEST_URI'], 'meow') !== false):?>
    description of the text meow
<?php else: ?> 
	not hahaha and not meow
<?php endif; ?>

About admin

Hi there! My name is Iryna, I am a web developer from Ukraine. While working on freelance projects I often face different technical issues and in this blog I publish articles on how to solve them. I am also interested in digital drawing and in this blog you will find brief tutorials that helped me and hopefully can help you as well.

Check Also

How to remove 404 //fonts.gstatic.com and //fonts.googleapis.com from WordPress head section

I tried solutions with functions that should remove from head and , but a very …

Leave a Reply

Your email address will not be published. Required fields are marked *