PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
moran1409
Forum Newbie
Posts: 13 Joined: Wed Feb 23, 2011 12:45 pm
Post
by moran1409 » Wed Feb 23, 2011 1:15 pm
i get the error for this code:
Code: Select all
<?php
$news = fopen("test.txt", "rb");
while (!feof($news) ) {
$line = fgets($news);
$parts = explode('=', $line);
print $parts[0] . $parts[1]. "<BR>";//line 60!!!
}
fclose($news);
?>
i know that this means that the array gets one argument instead of two but i do'nt know how to solve it...
this code works fine in my localhost but not on the server
McInfo
DevNet Resident
Posts: 1532 Joined: Wed Apr 01, 2009 1:31 pm
Post
by McInfo » Wed Feb 23, 2011 1:58 pm
What do you want your program to do with lines that do not contain "="?
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Feb 23, 2011 2:22 pm
Basically it looks like you're just taking the '=' out right? Why not just do a
str_replace() ?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
moran1409
Forum Newbie
Posts: 13 Joined: Wed Feb 23, 2011 12:45 pm
Post
by moran1409 » Wed Feb 23, 2011 3:17 pm
thanks for the help, i solved it and this is the solution:
Code: Select all
<?php
$news = fopen("test.txt", "rb");
while (!feof($news) ) {
$line = fgets($news);
$parts = explode('=', $line);
if(count($parts) == 2) {
echo $parts[0] , $parts[1], '<br>';
} else {
echo $parts[0], '<br>';
}
}
fclose($news);
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Feb 23, 2011 4:05 pm
You could replace
Code: Select all
if(count($parts) == 2) {
echo $parts[0] , $parts[1], '<br>';
} else {
echo $parts[0], '<br>';
}
with
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.