PHP : Check if a string contains a substring

In this this tutorial learn How to Check if a string contains a substring in php using a strpos() method - programming technology world

function str_contains(string $string, string $substr): bool
{
    return strpos($string, $substr) !== false;
}



TUTORIAL

<?php
/**
 * Check if a string contains a substring
 *
 * @param string $string
 * @param string $substr
 * @return bool
 */
function str_contains(string $string, string $substr): bool
{
    return strpos($string, $substr) !== false;
}


var_dump( str_contains("This is test!", "test!"));

OUTPUT DEMO

bool(true)


No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...