How do I check if a string contains a specific word?

Submitted 4 years, 6 months ago
Ticket #209
Views 333
Language/Framework Html
Priority Low
Status Closed

What is the correct way to write the statement if ($a contains 'are') for below code ??

$a = 'How are you?';

if ($a contains 'are')
    echo 'true';

Submitted on Oct 05, 20
add a comment

2 Answers

Verified

def isWordIn(word, string):
    return not(string.find(word) == -1)

Submitted 4 years, 6 months ago

<!DOCTYPE html>
<html>
<body>

<?php
$a = 'How are you?';
$word='are';
if(strpos($a, $word) !== false){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}

?>

</body>
</html>

Submitted 4 years, 6 months ago


Latest Blogs