I have this regexp to post edonkey links that replace this
to this:
Here an example of edonkey link:
This part 731744256 is the size's file in bytes.
So, I would like know if is there a regexp to get this part of link and format to something more human (like 697.85 MB, for example) because the $size in original function only work for me when there arent't anything above the edonkey link.
The original function is this:
And here is the humanize_size function:
Any help would be great.
Code:
"#(^|(?<=[^\w\"']))(ed2k://\|file\|([^\\/\|:<>\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i"
Code:
<a href='http://www.emugle.com/details.php?f=\\5' target='_blank'><img src='http://www.mistershare.org/home/images/misc/emugle-icon.gif' border='0'></a> <img src='http://www.mistershare.org/home/images/misc/emule.gif' border='0'> <a href='\\2'>\\3 <b>($size)</b></a>"
Code:
ed2k://|file|[Ubuntu.Linux.6.06].ubuntu-6.06-desktop-i386.iso|731744256|FB73A6DBAEFDFB7969FFD8CE8E4FC6E3|/
So, I would like know if is there a regexp to get this part of link and format to something more human (like 697.85 MB, for example) because the $size in original function only work for me when there arent't anything above the edonkey link.
The original function is this:
Code:
//######## INICIO HACK EDONKEY LINKS ########
$text = ' ' . $text;
$size = humanize_size(preg_replace("#(^|(?<=[^\w\"']))(ed2k://\|file\|([^\\/\|:<>\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i", "\\4", $text));
$patterns[] = "#(^|(?<=[^\w\"']))(ed2k://\|file\|([^\\/\|:<>\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i";
$replacements[] = "<a href='http://www.emugle.com/details.php?f=\\5' target='_blank'><img src='http://www.mistershare.org/home/images/misc/emugle-icon.gif' border='0'></a> <img src='http://www.mistershare.org/home/images/misc/emule.gif' border='0'> <a href='\\2'>\\3 <b>($size)</b></a>";
//######### FIM HACK EDONKEY LINKS ##########
And here is the humanize_size function:
Code:
<?php
function humanize_size ($size, $rounder = 0, $min = '')
{
$sizes = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$rounders = array(0, 1, 2, 2, 2, 3, 3, 3, 3);
$ext = $sizes[0];
$rnd = $rounders[0];
if ($min == 'KB' && $size < 1024)
{
$size = $size / 1024;
$ext = 'KB';
$rounder = 1;
}
else
{
for ($i=1, $cnt=count($sizes); ($i < $cnt && $size >= 1024); $i++)
{
$size = $size / 1024;
$ext = $sizes[$i];
$rnd = $rounders[$i];
}
}
if (!$rounder)
{
$rounder = $rnd;
}
return round($size, $rounder) . ' ' . $ext;
}
?>
Comment