Is there a presence of a PHP string?
In PHP, you can use the strpos() function to check if one string exists within another string. This function will return the position of the first occurrence of the first string within the second string, or false if not found.
Here is an example code:
$str1 = "Hello, world!";
$str2 = "world";
if (strpos($str1, $str2) !== false) {
echo "字符串存在";
} else {
echo "字符串不存在";
}
In the above code, strpos($str1, $str2) will return 7 because the substring “world” first appears in the main string “Hello, world!” starting at index 7. Therefore, the code will output “Substring found”.