includes in php code example
Example 1: php check if string contains word
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
Example 2: include and require in php
// Include a file, if it can't be found: continue.
<?php
include 'mainfile.php';
?>
// Alternatively: Require a file to be imported or quit if it can't be found
<?php
require 'requiredfile.php';
?>
Example 3: str_includes php
<?php
$string = 'The lazy fox jumped over the fence';
if (str_contains($string, '')) {
echo "Checking the existence of an empty string will always return true";
}
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string\n";
}
if (str_contains($string, 'Lazy')) {
echo 'The string "Lazy" was found in the string';
} else {
echo '"Lazy" was not found because the case does not match';
}
Example 4: contains php
if (strpos($a, 'are') !== false) {
echo 'true';
}