PHP check if a string contains a specific character

Viewed 3628

I have 2 strings $verify and $test. I want to check if $test contains elements from $verify at specific points. $test[4] = e and $test[9] = ]. How can I check if e and ] in $verify?

$verify = "aes7]";
$test = "09ske-2?;]3fs{";

if ($test[4] == $verify AND $test[9] == $verify) {
    echo "Match";
} else {
    echo "No Match";
}
2 Answers

As of PHP8 you can use str_contains()

<?php

$verify = "aes7]";
$test = "09ske-2?;]3fs{";

if (str_contains($verify, $test[4]) && str_contains($verify, $test[9])) {
    echo "Match";
} else {
    echo "No Match";
}
?>

Thanks to @symlink for the code snippet I butchered

Related