Home · Latest · Trends  /  PHP
3

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

rated 3 times [  3] [ 0]  / comments: 0 / hits: 736  / 1 year ago, mon, dec 4, 2017, 17:57:17
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;
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
 
Share
Snippets
CSS show image in a textarea with background tag
1 year ago, thu, dec 7, 2017
1 year ago, fri, feb 9, 2018
Redirect www to non-www URLs using htaccess
1 year ago, mon, feb 19, 2018
Posted
Nica Radi

Nica Radi

Member since Oct 29, 2017
Total Code Snippets: 4
Total Comments: 1
Location: n/a
Following
User not following anyone yet.