2015-02-20 7 views
-2

Привет У меня есть текстовый файл с содержимым, как это:Извлечение данных из текстового файла

{"Title":"Hot Tub Time Machine 2","Year":"2015","Rated":"R","Released":"20 Feb 2015","Runtime":"93 min","Genre":"Comedy, Sci-Fi","Director":"Steve Pink","Writer":"Josh Heald (characters), Josh Heald","Actors":"Adam Scott, Gillian Jacobs, Thomas Lennon, Chevy Chase","Plot":"When Lou, who has become the \"father of the Internet,\" is shot by an unknown assailant, Jacob and Nick fire up the time machine again to save their friend.","Language":"English","Country":"USA","Awards":"N/A","Poster":"http://ia.media-imdb.com/images/M/MV5BMTU3NzQzMzE0NV5BMl5BanBnXkFtZTgwMDM4MTI0N[email protected]_V1_SX300.jpg","Metascore":"N/A","imdbRating":"N/A","imdbVotes":"N/A","imdbID":"tt2637294","Type":"movie","Response":"True"} 

Я хочу, чтобы извлечь из него информацию и показать его на моем сайте.

+2

Это не просто «текстовый файл» , он содержит данные в формате [JSON data] (http://json.org/). Чтобы проанализировать его, вы используете [JSON Parser] (http://php.net/manual/en/book.json.php). – dimo414

ответ

1

Поскольку это текст JSON вы можете использовать что-то вроде этого:

$content = file_get_contents('http://mo4vies.esy.es/wp-content/uploads/imdbcache/tt2637294.txt'); 
$contentArray = json_decode($content, true); 

$contentArray будет ассоциативный массив со структурой, как это:

array(20) { 
    ["Title"]=> 
    string(22) "Hot Tub Time Machine 2" 
    ["Year"]=> 
    string(4) "2015" 
    ["Rated"]=> 
    string(1) "R" 
    ["Released"]=> 
    string(11) "20 Feb 2015" 
    ["Runtime"]=> 
    string(6) "93 min" 
    ["Genre"]=> 
    string(14) "Comedy, Sci-Fi" 
    ["Director"]=> 
    string(10) "Steve Pink" 
    ["Writer"]=> 
    string(35) "Josh Heald (characters), Josh Heald" 
    ["Actors"]=> 
    string(54) "Adam Scott, Gillian Jacobs, Thomas Lennon, Chevy Chase" 
    ["Plot"]=> 
    string(155) "When Lou, who has become the "father of the Internet," is shot by an unknown assailant, Jacob and Nick fire up the time machine again to save their friend." 
    ["Language"]=> 
    string(7) "English" 
    ["Country"]=> 
    string(3) "USA" 
    ["Awards"]=> 
    string(3) "N/A" 
    ["Poster"]=> 
    string(96) "http://ia.media- imdb.com/images/M/[email protected]_V1_SX300.jpg" 
    ["Metascore"]=> 
    string(3) "N/A" 
    ["imdbRating"]=> 
    string(3) "N/A" 
    ["imdbVotes"]=> 
    string(3) "N/A" 
    ["imdbID"]=> 
    string(9) "tt2637294" 
    ["Type"]=> 
    string(5) "movie" 
    ["Response"]=> 
    string(4) "True" 
} 
Смежные вопросы