Example 1 — Get the Last Part of a Path
Find the final slash and take everything after it.
<?php
$path = "/var/www/index.php";
$file = strrchr($path, "/");
echo $file, PHP_EOL; How It Works
- Store a file path.
- Search for the last "/".
- strrchr returns the text starting at that slash.
- The result still includes the slash itself.

