PHP Using String Matching Vs. Pattern Matching – String Function

<?php $value = "my username";
if (strcmp($value, "user") == 0) {
    echo "Found match in '" . $value . "' using strcmp.\n";
} else {
    echo "Didn't find match in '" . $value . "' using strcmp.\n";
}
if (!(strrpos($value,"user") ==="false)) {
    echo "Found match in '" . $value . "' using strrpos.\n";
} else {
    echo "Didn't find match in '" . $value . "' using strrpos.\n";
}
if (ereg("\<user\>", $value)) {
    echo "Found match in '" . $value . "' using ereg.\n";
} else {
    echo "Didn't find match in '" . $value . "' using ereg.\n";
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.