Functions str_starts_with and str_ends_with in PHP: how to check the start and end of a string?
Hello everyone! I just started learning PHP and ran into a problem. I need to check if a string starts with a certain word or ends with a certain character. For example, I receive an email from a user and want to make sure it ends with "@gmail.com" or starts with "admin_". \n\nI know that PHP has many built-in functions for working with strings, but I can't find a simple way to do this. I tried using substr() and comparing, but the code ends up being cumbersome:\n\n```php\n$email = "admin_test@gmail.com";\nif (substr($email, 0, 6) === "admin_") {\n echo "This is an admin email";\n}\nif (substr($email, -10) === "@gmail.com") {\n echo "This is Gmail";\n}\n```\n\nThis works, but I think there is a more elegant solution. I heard that Python has a method