PHP method to get file extension from given url_PHP Tutorial

WBOY
Release: 2016-07-13 10:03:12
Original
848 people have browsed it

How php gets the file extension from a given url

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969339.htmlTechArticleHow to get the file extension in php from a given url. This article explains how to get the file extension in php from a given url. method. Share it with everyone for your reference. The specific implementation method is as follows: ?php...
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