For example;
"Real Madrid" -> false
"Barcelona " -> true
with what functions can I solve this in laravel?
For example;
"Real Madrid" -> false
"Barcelona " -> true
with what functions can I solve this in laravel?
A string is a single word if it:
function isSingleWord(string $input): bool
{
// Check for empty string - "" isn't a word
if (empty($input)) {
return false;
}
// Check for whitespace of any kind
return !preg_match('/\s/', $input);
}
you can use
$result = explode(' ', trim("barcelona "));
print_r($result);
trim will remove all white space at the beginning and the end of your string