strpos()
FunctionYou can use the PHP strpos()
function to check whether a string contains a specific word or not.
The strpos()
function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false
. Also note that string positions start at 0, and not 1.
Let's check out an example to understand how this function basically works:
<?php
$word = "fox";
$mystring = "The quick brown fox jumps over the lazy dog";
// Test if string contains the word
if(strpos($mystring, $word) !== false){
echo "Word Found!";
} else{
echo "Word Not Found!";
}
?>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
Bootstrap Typehead Demo with PHP and MySql
In this post, i am going to show you how...How to find number of characters in a string in PHP
Use the PHP strlen() function...Laravel 7 Send Mail Using Markdown Example
Today, markdown laravel 7 mail is our ma...How to Strip All Spaces Out of a String in PHP
Use the PHP str_replace() Function Yo...Auto Complete City Google Map API In Laravel
Hello, everyone in this tutorials we are...