php contains substring

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

3.5
2
ROSS 90 points

                                    $a = 'How are you?';

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

3.5 (2 Votes)
0
0
0
John Manak 160 points

                                    <?php
function g($string,$start,$end){
     preg_match_all('/' . preg_quote($start, '/') . '(.*?)'. preg_quote($end, '/').'/i', $string, $m);
     $out = array();

     foreach($m[1] as $key => $value){
       $type = explode('::',$value);
       if(sizeof($type)>1){
          if(!is_array($out[$type[0]]))
             $out[$type[0]] = array();
          $out[$type[0]][] = $type[1];
       } else {
          $out[] = $value;
       }
     }
  return $out;
}
print_r(g('Sample text, [/text to extract/] Rest of sample text [/WEB::http://google.com/] bla bla bla. ','[/','/]'));
?>

results:
Array
(
    [0] => text to extract
    [WEB] => Array
        (
            [0] => http://google.com
        )

)

Can be helpfull to custom parsing :)
  

0
0
4
5
Enthusiast 95 points

                                    
<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?>

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 starting includes substring strpos in php 7.4 php function to check if string contains substring strpos() php php string.contains check if string contains a sentence php check if string contains substrings php check if string contains character php is substring php strpos in php\ php string contain php if string contains substring substring contains php string contains substring php php check if string contains character strpos php 7.4 check if substring is in string php string contain php sub contain char from string php strpos() php how to know if a string contains a value php strin cointain dtring if string contains substring php php contain string php is string contains match substring in php php if text contains string php if string containt string check if string contains exact substring php strpos in php if contains chech of string contsins a word php php string contains word php substring exists What is the purpose of strpos() function of PHP? what is the use of strpos() function in php string contains string php php string containes strpos() in php php if string not contains check if string contains substring php string contains some characters php contains string true php php in substring in sting php variable contains substring php check string contains if string contains word php check if string contain word php string contains in php php check if a substring exists in a string php if contain string php check if string contains word php string contains char php string includes char how to check if string contains substring php php variable contains specific string php end of string contains substring contains letter php strpos function in php php string contains substring at positon php if contains string php is substring php check if string contains contains in stringin php if string contains words php check string contains php php string contains strpos in php strpos php strpos is_substring php string contains other php php is substring exists instr php syntax substr php indexof snmp php how to check if a string contains something in php check if string is in string php php for in string containing a string php php string contains substring string includes php string get index php how to compare the variable in strpos in laravel php check if string contains string strpos for link php strpos result find string in ph how to check if a string contains a character php php string find char pos php get string position php contains string str.includes in php search collection strpos php string like php string is in string php has no characters php contains string in string php if string contains character php if string contain php find char position in string ition find a letter position in a sentence php php if character in string find if a certain word is in a string php php i string contain php check text in string php search one string in onother php search a string from string php substr exist php str_contains if in string php php if substring in string string containes php check if substring php php containe get strpos after specific index check string and php php check substring in string contains in php .contains() in php subscring find in php php found in check if substring in string php how to find a string in a strting php string contains php php string contains character php contains substring fine first occurance of needle in string without strpos index of character in string in php php is string in string php strings conteins php str contains strpos( php strpos example check string on string php string position in php php contains php if string contains includes string php how to find a character in a string in php strtime in php if string contains php how to search text in strin php strpose php find in string pgp how to find string in string in php POS PHP as an srgumnet str contains php str pos php get index of a character from string strval in php locate string php check if letter is in string php tstrpos in php == javascript strgtr php string match php strstr php check substr in str php find in php string or search for text in string php string contains index php php string countain php strin countain php find a string in a string search for a word in php using strpos find string in the string php is string contain php find string pos php find char in string php if (strpos($var) != false match in string php check a string for a string php strpos twee strpos php if why search string fails php strpos true php stringpos strpos 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