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

怪我咯
Release: 2023-03-12 18:50:01
Original
1408 people have browsed it

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";
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!