473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

empty lines

i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?
Jul 17 '05 #1
18 3037
"Piotr Wolski" wrote:
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?


foreach ($inarr as $out) {
if ($out <> ’’) echo $out . "\n";
}

or instead of \n use <br> if writing to browser.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-empty-li...ict140418.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=469648
Jul 17 '05 #2
steve wrote:
"Piotr Wolski" wrote:
> i read the filr into an array using file().
> some of the lines are empty. i would like to output the file but
> ignoring the emnpty lines. any ideas?


foreach ($inarr as $out) {
if ($out <> ’’) echo $out . "\n";
}

or instead of \n use <br> if writing to browser.

unfortunately it didint help. output is still the same.

$plik = fopen("wynik","r");
$tablica = file('wynik');

foreach ($tablica as $out) {
if ($out <> ' ') echo $out."\n";
}

Jul 17 '05 #3
On Tue, 17 Aug 2004 11:31:19 -0500, Piotr Wolski wrote:
steve wrote:
"Piotr Wolski" wrote:
> i read the filr into an array using file().
> some of the lines are empty. i would like to output the file but
> ignoring the emnpty lines. any ideas?
foreach ($inarr as $out) {
if ($out <> '') echo $out . "\n";
}

or instead of \n use <br> if writing to browser.

unfortunately it didint help. output is still the same.

$plik = fopen("wynik","r");
$tablica = file('wynik');

foreach ($tablica as $out) {
if ($out <> ' ') echo $out."\n";

^^ ^ }

m$ style "not" (<>) and a space you're checking against. Try:
foreach ($tablica as $out) {
if (strlen($out) > 0) echo "$out\n";
}
Note:

if ($out != '') echo "$out\n";
could also be used, depending on your preferred coding style =)

HTH.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #4
Ian.H wrote:
On Tue, 17 Aug 2004 11:31:19 -0500, Piotr Wolski wrote:

steve wrote:
"Piotr Wolski" wrote:
> i read the filr into an array using file().
> some of the lines are empty. i would like to output the file but
> ignoring the emnpty lines. any ideas?

foreach ($inarr as $out) {
if ($out <> '') echo $out . "\n";
}

or instead of \n use <br> if writing to browser.


unfortunately it didint help. output is still the same.

$plik = fopen("wynik","r");
$tablica = file('wynik');

foreach ($tablica as $out) {
if ($out <> ' ') echo $out."\n";


^^ ^
}


m$ style "not" (<>) and a space you're checking against. Try:
foreach ($tablica as $out) {
if (strlen($out) > 0) echo "$out\n";
}
Note:

if ($out != '') echo "$out\n";
could also be used, depending on your preferred coding style =)

HTH.

Regards,

Ian

i' wondering whats wrong cause the result is the same..
here is my code:

echo '<br><textarea name="show" rows=24 cols=40>';

exec($program." >wynik");
$plik = fopen("wynik","r");

$tablica = file('wynik');

foreach ($tablica as $out) {
if (strlen($out)>0) echo $out;

}
echo '</textarea>';
end the output in textarea is still the same:
I = 0
J = 0
sum2 = 0.000000
sum = 0.000000
Alpha 1 = 0.000000
Alpha = NaN
total = 0

percentage is = 0.000000%

....

i dont want to have this empty lines..
Jul 17 '05 #5
Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...

i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?


$data = file('file.txt');
foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line;
}
}

Cheers,
NC
Jul 17 '05 #6
"Piotr Wolski" <wo****@cs.purdue.edu> wrote in message
news:cf**********@mozo.cc.purdue.edu...
Ian.H wrote:
On Tue, 17 Aug 2004 11:31:19 -0500, Piotr Wolski wrote:

steve wrote:

"Piotr Wolski" wrote:
> i read the filr into an array using file().
> some of the lines are empty. i would like to output the file but
> ignoring the emnpty lines. any ideas?

foreach ($inarr as $out) {
if ($out <> '') echo $out . "\n";
}

or instead of \n use <br> if writing to browser.
unfortunately it didint help. output is still the same.

$plik = fopen("wynik","r");
$tablica = file('wynik');

foreach ($tablica as $out) {
if ($out <> ' ') echo $out."\n";


^^ ^
}


m$ style "not" (<>) and a space you're checking against. Try:
foreach ($tablica as $out) {
if (strlen($out) > 0) echo "$out\n";
}
Note:

if ($out != '') echo "$out\n";
could also be used, depending on your preferred coding style =)

HTH.

Regards,

Ian

i' wondering whats wrong cause the result is the same..
here is my code:

echo '<br><textarea name="show" rows=24 cols=40>';

exec($program." >wynik");
$plik = fopen("wynik","r");

$tablica = file('wynik');

foreach ($tablica as $out) {
if (strlen($out)>0) echo $out;

}
echo '</textarea>';
end the output in textarea is still the same:
I = 0
J = 0
sum2 = 0.000000
sum = 0.000000
Alpha 1 = 0.000000
Alpha = NaN
total = 0

percentage is = 0.000000%

...

i dont want to have this empty lines..


Maybe try a simple regexp? Ex:

foreach ($tablica as $out) {
if ( strlen( $out ) > 0 && preg_match( "/\S/", $out, $tmp ) echo $out;
}
Jul 17 '05 #7
Nikolai Chuvakhin wrote:
Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?

$data = file('file.txt');
foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line;
}
}

Cheers,
NC

yes, this is ok:). thank you very much, however i dont know why other
solutions were not correct.
Jul 17 '05 #8
Piotr Wolski wrote:
Nikolai Chuvakhin wrote:
Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?


$data = file('file.txt'); foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line; }
}

Cheers, NC


yes, this is ok:). thank you very much, however i dont know why other
solutions were not correct.

if in my file for example in the middle of the file is a word "blabla".
How than i can find this word?
i'd like to use in inside this code if its possible and make this
"blabla" bold <b>:

$data = file('file.txt'); foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line; } }
Jul 17 '05 #9
Piotr Wolski wrote:
Piotr Wolski wrote:
Nikolai Chuvakhin wrote:
Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...

i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?


$data = file('file.txt'); foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line; }
}

Cheers, NC

yes, this is ok:). thank you very much, however i dont know why other
solutions were not correct.


if in my file for example in the middle of the file is a word "blabla".
How than i can find this word?
i'd like to use in inside this code if its possible and make this
"blabla" bold <b>:

$data = file('file.txt'); foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line; } }


and one more question. can i somehow use html tags inside <textarea>
??for example i want to use <hr> tag.
Jul 17 '05 #10
On Tue, 17 Aug 2004 13:40:47 -0500, Piotr Wolski wrote:
Nikolai Chuvakhin wrote:
Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?

$data = file('file.txt');
foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line;
}
}

Cheers,
NC

yes, this is ok:). thank you very much, however i dont know why other
solutions were not correct.

It's caused by the newline char (\n). While the line appears empty (as it
would in a text editor), there is infact an "invisible" chart at the end
noting that a newline should be used. trim() strips off the \n char from a
string, thus resulting in a completely empty string which then gives the
output you were expecting =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #11
On Tue, 17 Aug 2004 13:44:41 -0500, Piotr Wolski wrote:
Piotr Wolski wrote:
Nikolai Chuvakhin wrote:
Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...

i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?

$data = file('file.txt'); foreach($data as $line) {
if (strlen(trim($line)) > 0) {
echo $line; }
}

Cheers, NC
yes, this is ok:). thank you very much, however i dont know why other
solutions were not correct.

if in my file for example in the middle of the file is a word "blabla".
How than i can find this word?
i'd like to use in inside this code if its possible and make this
"blabla" bold <b>:

$data = file('file.txt'); foreach($data as $line) {
if (strlen(trim($line)) > 0) {


$line = str_replace('blabla', '<b>blabla</b>', $line);
echo $line;
} }

Should work.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #12
here's an idea:

foreach ( $lines as $line )
if ( !empty($line) )
echo $line;

Piotr Wolski <wo****@cs.purdue.edu> wrote in message news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?

Jul 17 '05 #13
here's an idea:

foreach ( $lines as $line )
if ( !empty($line) )
echo $line;

Piotr Wolski <wo****@cs.purdue.edu> wrote in message news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?

Jul 17 '05 #14
here's an idea:

foreach ( $lines as $line )
if ( !empty($line) )
echo $line;

Piotr Wolski <wo****@cs.purdue.edu> wrote in message news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?

Jul 17 '05 #15
[ TOFU corrected: <http://tk.digiserv.net/tofu.txt]

Piotr Wolski <wo****@cs.purdue.edu> wrote in message
news:<cf**********@mozo.cc.purdue.edu>...
i read the filr into an array using file(). some of the lines are
empty. i would like to output the file but ignoring the emnpty lines.
any ideas?


On Tue, 17 Aug 2004 14:02:21 -0700, Brad Kent wrote:
here's an idea:

foreach ( $lines as $line )
if ( !empty($line) )
echo $line;


0
0
0
The above 3 lines are empty according to the empty() function, which would
skip these, maybe not the actions the OP would like =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #16

"Piotr Wolski" <wo****@cs.purdue.edu> wrote in message
news:cf**********@mozo.cc.purdue.edu...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?


array_map() and array_filter() are definitely under-utilitized...

$tablica = array_filter(array_map('rtrim', file('wynik.txt')));
--
Obey the Clown - http://www.conradish.net/bobo/
Jul 17 '05 #17
"Piotr Wolski" wrote:
steve wrote:
"Piotr Wolski" wrote:
> i read the filr into an array using file().
> some of the lines are empty. i would like to output the file but > ignoring the emnpty lines. any ideas?


foreach ($inarr as $out) {
if ($out <> ’’) echo $out . "\n";
}

or instead of \n use <br> if writing to browser.

unfortunately it didint help. output is still the same.

$plik = fopen("wynik","r");
$tablica = file(’wynik’);

foreach ($tablica as $out) {
if ($out <> ’ ’) echo $out."\n";
}


Piotr, you have a space between the single quotes in "($out <> ’ ’)
".
Remove the space and it works. The other solutions with strlen do
the same thing.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-empty-li...ict140418.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=470470
Jul 17 '05 #18
On Wed, 18 Aug 2004 00:11:24 -0400, "Chung Leong" <ch***********@hotmail.com>
wrote:
"Piotr Wolski" <wo****@cs.purdue.edu> wrote in message
news:cf**********@mozo.cc.purdue.edu...
i read the filr into an array using file().
some of the lines are empty. i would like to output the file but
ignoring the emnpty lines. any ideas?


array_map() and array_filter() are definitely under-utilitized...

$tablica = array_filter(array_map('rtrim', file('wynik.txt')));


Careful with zeroes...

<pre>
<?php
print_r(file('wynik.txt'));

print "\n\n";

$tablica = array_filter(array_map('rtrim', file('wynik.txt')));
print_r($tablica);

print "\n\n";

$tablica = array_filter(array_map('rtrim', file('wynik.txt')), 'strlen');
print_r($tablica);

?>
</pre>

Output:

Array
(
[0] => 0

[1] =>

[2] => blah
)
Array
(
[2] => blah
)
Array
(
[0] => 0
[2] => blah
)

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
9
by: ted | last post by:
I'm having trouble using the re module to remove empty lines in a file. Here's what I thought would work, but it doesn't: import re f = open("old_site/index.html") for line in f: line =...
6
by: mary | last post by:
When we use string line; while (getline(in,line)) { out.write(line.c_str(),line.size()); out.put('\n'); } in.close();
1
by: Benny Eckert | last post by:
Hi everyone, There's probably an easy solution to this little problem, but I can't find it: in the properties of my field, i selected hide duplicates 'yes'. As a (logical) result, i have a...
7
by: Matthew Wieder | last post by:
Hi - I have a datagrid that has a black header and the rows alternate white and gray. The problem is that until items are added to the grid, the grid appears as a large black rectangle, which is...
5
by: Sen Haerens | last post by:
I'm using string.split(/^$/m, 2) on a curl output to separate header and body. There’s an empty line between them. ^$ doesn’t seem to work... Example curl output: HTTP/1.1 404 Not Found...
2
by: Rico | last post by:
Hello, I'm formatting a report based on an existing controlled document. The document that I'm duplicating has a number of lines that the user fills our manually, but the database version of...
5
by: LEM | last post by:
Hi, I'm trying to remove any empty lines from a string, and I am doing the following: String pp; pp = "\r\n\r\n1\r\n23\r\n\r\n4"; pp = pp.Replace("\r\n\r\n", "\r\n");
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.