Check if a String Contains a Substring in PHP

$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}

4.25
4
TedEwen 110 points

                                    phpCopy<?php
$mystring = "This is a PHP program.";

if (strpos($mystring, "PHP", 13) !== false) {
    echo("True");
} else {
    echo("False");
}
?>

4.25 (4 Votes)
0
4.43
7

                                    phpCopy<?php
$mystring = "This is a PHP program.";

if (strpos($mystring, "program.") !== false) {
    echo("True");
}
?>

4.43 (7 Votes)
0
3.75
8

                                    $a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}

3.75 (8 Votes)
0
4
6
Synai 105 points

                                    phpCopy<?php
$mystring = "This is a php program.";
$search = "a";
if(preg_match("/{$search}/i", $mystring)) {
    echo "True"; } else {
    echo("False");
}
?>

4 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
php check if string contains word check for substring php php check if value contains string check substring php check if contains substring php check string is present in string using php php check for substring check substring in string php how to check if string contains specific character in php php check string contains character php string contains text check a string contains a specific word php if string has substring php php check if substring exists php check if string is inside another string string contains a word in php how to check if a string is a substring of another php if string contain php check if string contains string php php contains string check php find string contains check if string has substring in php php substring exists in string check if string contains php\ check if contains caracter on string php if string contains string php php check string contains write a script to check whether a substring exist inside a string or not? php php if str contains php str contains substring php if variable contains str php check if string contains specific subset of characters Check if a string is substring of another in php if a substring is in a string in php php check if string contains character php if string contains word php check if string has character how to check substring in string php php check if substring exists in string how to check if string includes a word php check if string contains a value in php substring if php check if string contains substring php check substring exists in string php check the substring in php if word contains letter in php php check if string contains characters php check if string in string php if string contains substring php if substring in string php check if string contains string check if string contain substring in php check if a text contains a certain text php check string contains word in php check string contains in php check if substring in string php check if string contains php php check if string contains check string is present in string php check if string contains character php PHP check if string contains amount php check string contains string how to check if a string contains a substring php check if string has the word php php function check if string contains php check if string contains substring php if string contains check if a string contains a substring php php if sub str exist how to see if string contains substring php see if string contains a word php if substring in string php check if word contain string php how to check a string contains a words in pohp how to check if a string contains a word in php php check substring search if string contains php php if text contains letters php find if string contains php check if a string contains a substring how to check if string is a substring of another string in php check if string exists in string php check if a string contains a word php check if string has substring php check if a string contains a caracter php how to check if a string contain another string php how to know if sub string in string in php php str contains substr check if a string has a character php php if substring exists if string contains php check if substring is present in string php how to check if substring contains substring php check substring present php php string contains substring check if substring exists in string php check if string contains substring array php
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source