Home  >  Article  >  Backend Development  >  Detailed explanation of how php gets the file extension from a given url

Detailed explanation of how php gets the file extension from a given url

怪我咯
怪我咯Original
2017-07-05 10:46:061367browse

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(&#39;.&#39;, $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!

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