How to check if a string starts with a given substring in PHP?
Hello everyone! I'm new to PHP and encountered this task: I need to check if a string starts with a specific word or character. For example, I have a variable with a file name:\n\n```php\n$filename = "report_2023.pdf";\n```\n\nI need to find out if this string starts with "report_". In JavaScript I would use `startsWith()`, but PHP doesn't have such a method. I tried using `strpos`:\n\n```php\nif (strpos($filename, "report_") !== false) {\n echo "Starts with report_";\n}\n```\n\nBut this checks if the substring exists anywhere in the string, not just at the beginning. If the file is named "my_report_2023.pdf", the condition will also trigger, but I need it strictly at the start. I also tried `substr`:\n\n```php\nif (substr($filename, 0, 7) === "report_") {\n echo "Starts with report_";\n}\n```\n\nThis works