Example 1 — Check a File Extension
Test the end of a file name.
<?php
$file = "report.pdf";
if (str_ends_with($file, ".pdf")) {
echo "This is a PDF", PHP_EOL;
} How It Works
- Pick a file name. It ends with
.pdf. - Call str_ends_with(). String first, ending second.
- Get true. The ending matches.
- Run the if block. The message prints.

