Reputation: 41
Ok I have this script that should be getting the results from http://www.omdbapi.com/
<?php
$doc = new DOMDocument;
$filePath = 'data.txt';
if(file_exists($filePath)) {
$file = fopen($filePath,'r');
while(!feof($file)) {
$name = fgets($file);
echo $name;
$doc->loadhtmlfile('http://www.omdbapi.com/?i=&t=' . $name . '&r=JSON&plot=full');
$body = $doc->getElementsByTagName('body');
if ( $body && 0<$body->length ) {
$body = $body->item(0);
echo $doc->savehtml($body);
}
sleep(1);
}
fclose($file);
}
else {
echo "FNF!";
}
?>
This is the script and this is the file I'm using
Planet Earth
Game of Thrones
Breaking Bad
The Wire
Life
Sherlock
Arrested Development
Clanul Soprano
Firefly
Dexter
Avatar: The Last Airbender
Twin Peaks
Freaks and Geeks
Monty Python's Flying Circus
Roma
The Twilight Zone
Oz
Seinfeld
Deadwood
Desu nôto
House of Cards
South Park
Fawlty Towers
Batman
Prietenii tai
Leyla ile Mecnun
Cowboy Bebop
Suits
It's Always Sunny in Philadelphia
Blackadder Goes Forth
Six Feet Under
Downton Abbey
The Office
The Walking Dead
Archer
Dragon Ball Z
Black-Adder II
Familia Simpson
Top Gear
Boardwalk Empire
The X Files
Battlestar Galactica
Justified
Black Adder the Third
Futurama
Doctor Who
Spartacus: Blood and Sand
Mad Men
Dragon Ball Z
Spaced
And i get "movie not found" for every title except the last one(it doesn't matter which title i put last in the file). Can you tell me why's that happening?
Upvotes: 0
Views: 74
Reputation: 10239
Try:
$name = trim(fgets($file));
When you call fgets
it's returning the line with the newline at the end. The last line doesn't have a newline.
Upvotes: 2