Jump to content

Getting rid of the file extension.


ted_chou12

Recommended Posts

That won't work if the filename has more that one period in it.

[code]<?php
$fn = "test.one.two";
list($name,$ext) = explode('.',$fn);
echo $name."<br>";
echo $ext;
?>[/code]

will echo "one" for the extension.

A better way would be to use the [url=http://www.php.net/basename]basename()[/url] function.

[code]<?php
$fn = "test.one.two";
$pi = pathinfo($fn);
echo '<pre>' . print_r($pi,true) . '</pre>';
?>[/code]

Ken

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.