Log in

View Full Version : Strip extension


thesatman
08-01-2006, 05:53 PM
Hi, I want to strip the extension from a filename like- filename.gif i want it to only show- filename

This is the code i have at the moment to get the filename-


<?php

// ### TOP STATS ########################################

$top_stats = array();
// TOP POSTERS
$top_posters = $db->query_read("SELECT * FROM ".TABLE_PREFIX."attachment ORDER BY counter DESC LIMIT 10");
while($top_poster = $db->fetch_array($top_posters))
{
eval('$top_stats[\'top_posters\'] .= "' . fetch_template('top_posters') . '";');
}
unset($top_poster);
$db->free_result($top_posters);
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_topposters') . '";');


and this is the code i have in the style-


<tr>
<td class="thead"><span class="smallfont"><a href="http://www.mobileexpert.co.uk/mobile/forum/showthread.php?p=$top_poster[postid]">[$top_poster[filename]]</a></span>

<class="$bgclass"><span class="smallfont"><strong><a> </a>[$top_poster[counter]]</strong></span></td>
</tr>


at the moment it shows the 10 most downloaded files but including the file extension, Anyone know how i can strip the file extension please ?

Cheers
Chris.

Kaitlyn2004
08-01-2006, 06:14 PM
You can do...

$name = substr($filename, 0, strrpos($filename, '.'));

thesatman
08-01-2006, 06:35 PM
Thanks but how would i include that in the above code as i'm using-

$top_poster[filename]

in my style to display the 10 most downloaded files

Kaitlyn2004
08-01-2006, 06:56 PM
$name = substr($top_poster[filename], 0, strrpos($top_poster[filename], '.'));

thesatman
08-01-2006, 07:18 PM
Hey it worked :D Many thanks.

Kaitlyn2004
08-01-2006, 07:40 PM
Hey it worked :D Many thanks.

welcome :)

thesatman
08-01-2006, 07:49 PM
Thanks, Just 1 more quick question please :) how would i get it to only show the first say 15 letters of the file name-


$name = substr($top_poster[filename], 0, strrpos($top_poster[filename], '.'));


thanks
chris.

Kaitlyn2004
08-01-2006, 08:23 PM
Thanks, Just 1 more quick question please :) how would i get it to only show the first say 15 letters of the file name-


$name = substr($top_poster[filename], 0, strrpos($top_poster[filename], '.'));


thanks
chris.


$name = substr($top_poster[filename], 0, strrpos($top_poster[filename], '.'));
$name = substr($name, 0, 15);