[ciapug] Extract files used on a page

ciapug@cialug.org ciapug@cialug.org
Tue, 22 Feb 2005 18:05:03 -0600 (CST)


I already have a function to get the file size. I need something that will
parse HTML and get all the files its linking to (CSS,JS,images, etc).


Jon


> Well, you can make a parser using regular expressions that scans for
> tags and returns file names/paths according to type, and then pass them
> through some code like this (for $file, use a dynamic array and you can
> do a foreach() thing):
>
> |<?php
> function Getfilesize($file) {
>     $kb = 1024;         // Kilobyte
>     $mb = 1024 * $kb;   // Megabyte
>     $gb = 1024 * $mb;   // Gigabyte
>     $tb = 1024 * $gb;   // Terabyte
>
>     $size = filesize($file);
>     if($size < $kb) {
>         echo $size." B";
>     }
>     else if($size < $mb) {
>         echo round($size/$kb,2)." KB";
>     }
>     else if($size < $gb) {
>         echo round($size/$mb,2)." MB";
>     }
>     else if($size < $tb) {
>         echo round($size/$gb,2)." GB";
>     }
>     else {
>         echo round($size/$tb,2)." TB";
>     }
> }
>
> $file = "index.php"; // filename to check
> Getfilesize($file);
> ?>
>
> http://codeline-alley.digiserv.net/dis_code.php?snid=144&cid=&scid=
>
> Is that the idea?
>
> Darcy
> |
> jcbailey@code0.net wrote:
>
>>That script only calculates the PHP execution time. I want to take a
>>string (HTML file), extract any external links (images, external JS, CSS,
>>etc). and get those file sizes from an HTTP server.
>>
>>
>>
>>Jon
>>
>>
>
>