We can use the PHP strpos() Function to do that.

The strpos() function finds the position of the first occurrence of a string inside another string.

Syntax:


strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int

In simple terms,


strpos(the string to loon into, the string to find, start point of search)

First two parameters are required and third one is optional.

Example to search a word:


<?php
$word = "Yogesh";
$searchInThisString = "This website is Yogesh Chauhan's Blog";
 
if(strpos($searchInThisString, $word) !== false){
    echo "word found";
    //add more logic if you want
} else{
    echo "word NOT found";
    //add more logic if you want
}
?>

5 Comments

Bernardo

Mar 25, 2020 08:03:41 am

Thank you for another informative web site. The place else could I get that kind of information written in such a perfect manner? I've a undertaking that I'm simply now working on, and I have been on the look out for such info.

Rock

Mar 18, 2020 12:03:22 pm

Cool blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog shine. Please let me know where you got your design. With thanks

ninjalani

Mar 18, 2020 01:03:12 am

Simply want to say your article is as amazing. The clarity on your post is just cool and that i could assume you're a professional on this subject. Well together with your permission let me to grasp your RSS feed to keep updated with impending post. Thanks 1,000,000 and please continue the enjoyable work.

Jimmy

Mar 17, 2020 10:03:53 am

I feel this is among the so much significant information for me. And i'm glad reading your article. But want to observation on few basic things, The web site taste is wonderful, the articles is in point of fact excellent : D. Excellent task, cheers

Simmy

Mar 17, 2020 09:03:14 am

I like the helpful info you provide in your articles. I'll bookmark your weblog and check again here regularly. I'm quite certain I will learn many new stuff right here! Good luck for the next!

Leave a reply

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