Home >Backend Development >PHP Tutorial >PHP method to get file extension from given url, _PHP tutorial

PHP method to get file extension from given url, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:03:45973browse

How php gets the file extension from a given url,

The example in this article describes how php gets the file extension from a given url. Share it with everyone for your reference. The specific implementation method is as follows:

<&#63;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.bkjia.com/index.html&#63;id=1";
$str = getUrlPostfix($url);
echo $str . "\n";

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967738.htmlTechArticleHow to get the file extension in php from a given url. This example describes how to get the file extension in php from a given url. Name method. Share it with everyone for your reference. The specific implementation method is as follows: p...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn