This article mainly introduces the method of PHP getting the file extension from a given URL, involving the skills of PHP operating string, which has certain reference value. Friends who need it can refer to it
The example in this article describes how PHP obtains the file extension from a given URL. Share it with everyone for your reference. The specific implementation method is as follows:
<?php /** * 给定url,获取文件后缀 * @param string $url * @return string */ function getUrlPostfix ($url) { $url_arr = explode('.', $url); $postfix = $url_arr[count($url_arr) - 1]; $substr = substr($postfix, 0, 3); return $substr; } $url = "http://www.jb51.net/index.html?id=1"; $str = getUrlPostfix($url); echo $str . "\n";
The above is the detailed content of Detailed explanation of how php gets the file extension from a given url. For more information, please follow other related articles on the PHP Chinese website!