How can the pathinfo() function be used to extract file extensions from dynamic URLs in PHP?
To extract file extensions from dynamic URLs in PHP, you can use the pathinfo() function. This function parses a path and returns an associative array containing information about the path. To extract the file extension, you can access the 'extension' key in the array returned by pathinfo(). This allows you to easily retrieve and work with file extensions in dynamic URLs.
$url = "https://www.example.com/images/photo.jpg";
$extension = pathinfo($url, PATHINFO_EXTENSION);
echo $extension; // Output: jpg
Keywords
Related Questions
- What are alternative approaches or functions in PHP that can be used to achieve the same result as the code snippet provided in the forum thread for finding the largest number in an array?
- What is the purpose of using natsort() in the PHP code provided for the image gallery?
- What are the potential security risks of trying to reverse engineer an md5 hash in PHP for password retrieval?