Thu, October 21, 2021
 
https://devcodepro.comdevcodepro
X
Home · Latest · Trends
3

How to get clean file / image name with extension from the URL in PHP?

How to get clean file name / image name with extension from the URL with PHP?
$reg = '/(?<=jpg|png|gif|jpeg).*/';
$url = 'https://example.com/2012/12/zoe.jpg?w=600&#038;h=400&#038;crop=1,"; "=""';
$rep = '';
$result = preg_replace($reg, $rep, $url);
$cleanfile = basename($result);
echo $cleanfile;
rated 3 times (3) (0)
comments: 0 / hits: 2004  / 4 years ago, mon, dec 4, 17, 05:57:17
More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
Login with Google
 
Share
Posted
Nica Radi
Member since Oct 29, 2017
Total Code Snippets: 4
Total Comments: 1
Location: n/a
Nica Radi snippets
4 years ago, thu, dec 7, 17, 2:24:01
comments: 0 / hits: 1315
CSS
4 years ago, fri, feb 9, 18, 6:41:38
comments: 0 / hits: 1649
4 years ago, mon, feb 19, 18, 11:28:09
comments: 0 / hits: 1516