Tue, January 25, 2022
InterServer Web Hosting and VPS
https://devcodepro.comdevcodepro
X
InterServer Web Hosting and VPS
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: 2066  / 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
#textarea { border:#eee solid 1px; background:#fff url(images/myimage.png) no-repeat left 10px top 8px; } /* <textarea name="mytextarea" id="textarea"></textarea> */
comments: 0 / hits: 1374
CSS
4 years ago, fri, feb 9, 18, 6:41:38
<?xml version="1.0" ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>Site Name</title> <description>Site Description</description> <link>http://www.example.com</link> {section name=foo loop=$foo} <item> <title>{$foo[foo].progname|stripslashes|replace:"'":''|replace:'"':''|escape:'htmlall':'UTF-8'|replace:'&':' '}</title> <description>{$foo[foo].longdesc|htmlspecialchars_decode|strip_tags|escape|truncate:200}</description> <link>http://www.example.com/article.php?id={$foo[foo].articleid}</link> <guid>http://www.example.com/article.php?id={$foo[foo].articleid}</guid> <pubDate>{$foo[foo].date|date_format:"%a, %e %b %Y %H:%M:%S"} GMT</pubDate> </item> {/section} </channel> </rss>
comments: 0 / hits: 1717
4 years ago, mon, feb 19, 18, 11:28:09
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] </IfModule>
comments: 0 / hits: 1579