Jump to content

Reading an extension...


GremlinP1R

Recommended Posts

[quote author=obsidian link=topic=112006.msg454322#msg454322 date=1161262831]
or, an alternate method:
[code]
<?php
$ext = substr($filename, strrpos('.', $filename));
?>
[/code]
[/quote]

Doesn't work.
[code]<?php
$filename = "mysql.db.php";
$ext = substr($filename, strrpos('.', $filename));
echo $ext;
?>[/code]
outputs [quote=code output]mysql.db.php[/quote]
Link to comment
https://forums.phpfreaks.com/topic/24432-reading-an-extension/#findComment-111217
Share on other sites

[quote author=Daniel0 link=topic=112006.msg454326#msg454326 date=1161263193]
Doesn't work.
[/quote]

my bad, i switched the arguments for strrpos:
[code]
<?php
$filename = "mysql.db.php";
$ext = substr($filename, strrpos($filename, '.')+1);
echo $ext;
?>
[/code]

you could also just use a preg_match:
[code]
<?php
$filename = "mysql.db.php";
preg_match('|\.([a-z]+)$|i', $filename, $match);
$ext = $match[1];
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/24432-reading-an-extension/#findComment-111225
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.