In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
I believe many inexperienced people don't know what to do about how to get the file extension in PHP. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
/ / method 1:
Function extend_1 ($file_name)
{
$retval= ""
$pt=strrpos ($file_name, ".")
If ($pt) $retval=substr ($file_name, $pt+1, strlen ($file_name)-$pt)
Return ($retval)
}
/ / method 2
Php code
Function extend_2 ($file_name)
{
$extend = pathinfo ($file_name)
$extend = strtolower ($extend ["extension"])
Return $extend
}
Function extend_2 ($file_name) {$extend = pathinfo ($file_name); $extend = strtolower ($extend ["extension"]); return $extend;}
/ / method 3
Php code
Function extend_3 ($file_name)
{
$extend = explode (".", $file_name)
$va=count ($extend)-1
Return $extend [$va]
}
Function extend_3 ($file_name) {$extend = explode (".", $file_name); $va=count ($extend)-1; return $extend [$va];}
/ / method 4
Php code
Function getFileExt ($file_name)
{
While ($dot = strpos ($file_name, "."))
{
$file_name = substr ($file_name, $dot+1)
}
Return $file_name
}
? >
Function getFileExt ($file_name) {while ($dot = strpos ($file_name, ".")) {$file_name = substr ($file_name, $dot+1);} return $file_name;}? >
In addition:
PHP pathinfo () function
PHP Filesystem function
Definition and usage
The pathinfo () function returns information about the file path as an array.
Grammar.
Pathinfo (path,options)
Parameters.
Description
Path
Necessary. Specify the path to be checked.
Process_sections
Optional. Specifies the array elements to return. The default is all.
Possible values:
PATHINFO_DIRNAME-only dirname is returned
PATHINFO_BASENAME-only basename is returned
PATHINFO_EXTENSION-only extension is returned
Description
Pathinfo () returns an associative array containing information about path.
Includes the following array elements:
[dirname]
[basename]
[extension]
Tips and comments
Note: if all units are not required, the pathinfo () function returns a string.
Example Wuhan Renji Integrated traditional Chinese and Western Medicine Hospital http://www.whrjkf.com/
Example 1
Php code
/ / output:
/ / Array ([dirname] = > / testweb [basename] = > test.txt [extension] = > txt)
/ / output: / / Array ([dirname] = > / testweb [basename] = > test.txt [extension] = > txt)
After reading the above, have you mastered how to get the file extension in PHP? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.