included contents global

Busy's picture

He has: 6,151 posts

Joined: May 2001

I have a large included file (200kb) I want the sizeof() it which I can do if I include it, but can I make the sizeof variable global so it can be used without including the file?

list.inc.php // need sizeof() the contents of this file.
display.php // want to display the sizeof() results without including file
somethingelse.php // has the list.inc.php included but not using sizeof()

They have: 447 posts

Joined: Oct 1999

not sure exactly what you're asking. you can get the filesize of a file like so:

<?php
$size
= filesize('/path/to/the/file');
?>

Busy's picture

He has: 6,151 posts

Joined: May 2001

I know the filesize (200kb) but in that file is one big array, I need to disply the sizeof() results on another page without including that page if I can help it.

Thanks anyway

Busy's picture

He has: 6,151 posts

Joined: May 2001

I found something that will work with a bit of tweaking

<?php
$data_file
= \"list.inc.php\";
$the_list = file($data_file);
$list_total = sizeof($the_list);
?>

and the echo $list_total works but counts every line in the file, not the actual arrays lines. it works if i put the first and last lines on the same line as the first and last element.

Is there a better way, more true method?

They have: 447 posts

Joined: Oct 1999

other than reading the file and counting the lines, as you pointed out above, i dont think you can do this. you cant get the sizeof an array that doesnt exist.

why do you need to do this?

Busy's picture

He has: 6,151 posts

Joined: May 2001

I am doing this because I am having trouble doing it the database way andsince i am going away next week would like something up there that would work, but works properly.

The php manual is very good but is like a dictionary, trying to find a word you dont know how to spell.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.