Home > Backend Development > PHP Problem > What are the several ways to get the url extension in php

What are the several ways to get the url extension in php

青灯夜游
Release: 2023-03-15 08:52:02
Original
3221 people have browsed it

Obtaining method: 1. Use the "substr(strrchr($url,"."),1)" statement; 2. Use "substr($url,strrpos($url,'.') 1) " statement; 3. Use "pathinfo($url,PATHINFO_EXTENSION)".

What are the several ways to get the url extension in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php gets url extension Name method

Method 1:

<?php
$url="http://localhost/user/order.php";
function get_ext1($url){
	return substr(strrchr($url,"."),1);
}
echo get_ext1($url);
?>
Copy after login

What are the several ways to get the url extension in php

Method 2:

<?php
$url="http://localhost/user/order.php";
function get_ext2($url){
	$p=pathinfo($url);//Array ( [dirname] => http://localhost/user [basename] => order.php [extension] => php [filename] => order )
	return $p[&#39;extension&#39;];
}
echo get_ext2($url);
?>
Copy after login

Method 3:

<?php
$url="http://localhost/user/order.php";
function get_ext3($url){
	return substr($url,strrpos($url,&#39;.&#39;)+1);
}
echo get_ext3($url);
?>
Copy after login

Method 4:

<?php
$url="http://localhost/user/order.php";
function get_ext4($url){
	$arr=explode(&#39;.&#39;,$url);
	return array_pop($arr);
}
echo get_ext4($url);
?>
Copy after login

Method 5:

<?php
$url="http://localhost/user/order.php";
function get_ext5($url){
	return pathinfo($url,PATHINFO_EXTENSION);
}
echo get_ext5($url);
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are the several ways to get the url extension in php. 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