In PHP, what is the difference between using preg_match and strpos to check for the presence of a specific "string" in a line?

When checking for the presence of a specific string in a line, strpos is used to find the position of the first occurrence of a substring within a string. It returns the position as an integer or false if the substring is not found. On the other hand, preg_match is used for pattern matching using regular expressions. It returns true if the pattern is found in the string, otherwise false. The choice between the two methods depends on whether a simple string search or a more complex pattern matching is required.

// Using strpos to check for the presence of a specific string in a line
$line = "This is a sample line containing the word 'sample'";
$specificString = "sample";

if (strpos($line, $specificString) !== false) {
    echo "The specific string is present in the line.";
} else {
    echo "The specific string is not present in the line.";
}