This article describes the example of how php gets 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.bitsCN.com/index.html?id=1"; $str = getUrlPostfix($url); echo $str . "\n";
I hope this article will be helpful to everyone’s PHP programming design.