To Find the Occurrence of one string inside other :
We can use the strpos() function which is used to find the occurrence of one string inside other. For case-insensitive search we can use stripos() function.

Example 1 : Case-sensitive Search

 <?php

$myString = "Welcome to Code PHP Online";
$find = "Online";

if (strpos($myString, $find) !== false)
{
    echo "$myString contains $find";
}
else
{
    echo "$myString not contains $find";
}

?>

  /*

  Output :

  Welcome to Code PHP Online contains Online

  */
                            

Example 2 : Case-insensitive Search

 <?php

$myString = "Welcome to Code PHP Online";
$find = "online";

if (stripos($myString, $find) !== false)
{
    echo "$myString contains $find";
}
else
{
    echo "$myString not contains $find";
}

?>

  /*

  Output :

  Welcome to Code PHP Online contains online

  */
       
Rahul Yadav

Technical Architect

Kuala Lumpur, Malaysia

Connect Me:     

A web enthusiastic, self-motivated Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.

I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding, technical and digital learning experiences.

In my leisure time, I write articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Magento, Linux, Angular, Ionic, ReactJS, NodeJS, Cloud and more.

Tag Cloud