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 */
Technical Architect
Kuala Lumpur, Malaysia
I'm a 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 and technology learning experiences.
In my leisure time, I write technical articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Linux, Angular, Ionic, ReactJS, NodeJS, AJAX, jQuery, Cloud and more.