File Size for Linked File - line breaks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mbgritten
Forum Newbie
Posts: 7
Joined: Tue Jul 28, 2009 2:18 am

File Size for Linked File - line breaks

Post by mbgritten »

Hello,

I'm using the following code to generate a filesize for a linked file:

Code: Select all

<?php
$file_type = array( 'K', 'M', 'G' );
$size = filesize ( $f );
 
for ( $t = 0; $size > 1024; $t++ )
{
    $size /= 1024;
    
    $file_size = round ( $size, 1 ) . ' ' . $file_type[ $t ] . 'B';
}
 
$file_name =  substr($f, -(strlen($f) - strrpos($f,'/')));
echo "<a href=\"$f\" class=\"pdf\" title=\"$file_size\">";
list($f, $ext) = explode('.', $f);
echo basename($f);
echo " <small>($file_size)</small></a>";
?>
...and in the page I'd call the function by including:

Code: Select all

<?php $f = "My Event.pdf";?>
...which would echo:

Code: Select all

<a href="My Event.pdf" class="pdf" title="82 KB">My Event<small>(82 KB)</small></a>
 
However, for some reason the output is not working as planned. Instead of showing this:

Code: Select all

Watch out for [u]My Event (82 KB)[/u] - the vital source of LOCAL information. [u]Click here for more information[/u].
 
...the output is creating line breaks:

Code: Select all

Watch out for - the vital source of LOCAL information. [u]Click here for more information[/u].
 
My Event (82 KB)
Can anyone help explain why the output is taking the link outside of the paragraph and creating line breaks that shouldn't exist?

Thanks,

Mark
Post Reply