Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2008, 05:22 AM
Registered User
 
Join Date: Mar 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP problem with 1D matrix

Hello,
I write a script that looks into a directory, opens every file and reads these files into 1D matrix. Problem is that files have an empty lines.
My question is: how can I remove these empty entries from matrix ?
This is an example 1D matrix with empty entries.
Code:
[data1]
[]
[data2]
[data3]
[]
and here is my php code I use to read from files:
Code:
while($full_info[$i] = fgets ($fd,1024)){
//some code here
$i++;
}
I'll be glad for any help,
Best regards :)

 
Old April 14th, 2008, 06:20 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Programmers would normally say array rather than matrix, but if you find that easier to visualise then go for it.

All you need to do is check your line to see if its blank before putting it into your array.

Code:
// slurp into a temporary variable rather than straight into array
while($line = fgets ($fd,1024)){
  // Check that temporary variable is not an empty string
  // If it isn't, put it in array and increment array index
  if($line!=='') {
    $full_info[$i] = $line;
    $i++;
  }
  //some code here
}
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Print PHP Reports in Dot Matrix Printer brphp Pro PHP 1 September 12th, 2007 12:55 PM
Matrix problem anothervbaddict Reporting Services 0 August 2nd, 2007 02:18 AM
Matrix SubTotal Problem ramsk Reporting Services 0 November 20th, 2006 08:27 PM
Web Matrix Setup Problem kmoutsos Classic ASP Basics 1 August 9th, 2004 10:23 PM
install php on windows 2000 server (matrix) martinwbialachowski BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 May 6th, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.