LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2003, 12:47 AM   #1
HappyDude
Member
 
Registered: Jul 2003
Posts: 140

Rep: Reputation: 15
PHP array help?


Ok I've got a script that opens all the .txt files in directory then reads them. It then stores it in a array then sorts the array and prints the variable in the "0" spot. My problem is that as soon as I combine the variables for the last part of its script journey all but the first letter gets lost. For example if the file contained "41" it would print "4". I no pretty much where the problem is which happens to be this part:
Code:
for ($nu = 0; $nu <= $num; $nu++)
{
	$all[$nu] = "$buffer[$nu]$name[$nu]";
}
$buffer is the weird variable thats cutting its self. And now I realize you like to see the full sourcecode...
Code:
                    <?php
$num = 0;
chdir("pc");
foreach (glob("*.txt") as $filename) {
	$num++;
	$name[] = $filename;
}
$num--;
for ($nu = 0; $nu <= $num; $nu++)
	{ 
	if (!($fp = fopen($name[$nu], "r")))  
        exit("Unable to open the input file, $name[$nu].");
    $buffer[$nu] = fread($fp, filesize($name[$nu])); 
    fclose($fp);
} 
for ($nu = 0; $nu <= $num; $nu++)
{
	$all[$nu] = "$buffer[$nu]$name[$nu]";
}

	sort($all, SORT_NUMERIC);
	rsort($all);
	echo "$all[0]";
	
chdir("../");
?>
Does anyone see whats wrong and why it cuts? Please help....
 
Old 10-13-2003, 06:48 PM   #2
HappyDude
Member
 
Registered: Jul 2003
Posts: 140

Original Poster
Rep: Reputation: 15
Anyone? There must be someone...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Trouble to get Array Gerardoj Programming 5 03-28-2005 07:14 AM
php: array with functions ldp Programming 7 09-22-2004 04:55 PM
PHP Array Trouble Gerardoj Programming 2 05-30-2004 09:53 PM
multidimensional array (php) niehls Programming 2 01-31-2003 05:34 AM
php array gui10 Programming 2 03-26-2002 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration