Reputation: 37
I have a URL like below:
http://abc.def.com/gh-tqa/name-of-the-file/ZW607CCF.html
Now I want to get the string of ZW607CCF
without .html
.
How can I achieve this using PHP?
Upvotes: 0
Views: 63
Reputation: 2229
this is how you do:
$temp = explode('.', $_SERVER['PHP_SELF']);
$string = $temp[0];
with PHP 5.4+ you can also do:
$string = explode('.', $_SERVER['PHP_SELF'])[0];
Upvotes: 0
Reputation: 76646
You don't need a regex here. Just use pathinfo()
:
$url = 'http://abc.def.com/gh-tqa/name-of-the-file/ZW607CCF.html';
$filename = pathinfo($url, PATHINFO_FILENAME);
Upvotes: 10
Reputation: 39355
There are lot of ways in PHP, try preg_replace()
, for example:
$url = 'http://abc.def.com/gh-tqa/name-of-the-file/ZW607CCF.html';
$value = preg_replace("|.*/([^.]+)\.html|", "$1", $url);
Upvotes: 0