Monday , February 3 2025

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 iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

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 *