Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]file_get_contents()
Xander92
post
Post #1





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 1.09.2013

Ostrzeżenie: (0%)
-----


Witam

mam cos takiego

  1. $link = /lind_do_pliku.xml
  2. if(nie_odpowiada($link))
  3. {
  4. $niedziala == 'Brak informacji';
  5. }
  6. else
  7. {
  8. $pobierzdane = file_get_contents($link);
  9. }


I teraz co moge zrobic jak danych uzyc w arunku zyby :
gdy strona (jej host) z $ link nie odpowiada wyswietlic jakis test bo gdy to nie dziala strona sypie bledem
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
fate
post
Post #2





Grupa: Zarejestrowani
Postów: 824
Pomógł: 106
Dołączył: 14.03.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Mozesz wygluszyc sypanie bledem i nie wyswietlac nic
@file_get_contents($link);
(Ogolnie na produkcji i tam raportowanie bledow powinienes miec wylaczone zw bezpieczenstwa)

albo w warunek użyj np.
if
http://fi1.php.net/get_headers
TRUE

Ten post edytował fate 12.12.2013, 11:22:55


--------------------
Go to the top of the page
+Quote Post
Xander92
post
Post #3





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 1.09.2013

Ostrzeżenie: (0%)
-----


  1. $link = '/lind_do_pliku.xml';
  2. $cos = get_headers($link);
  3. if($cos== folse)
  4. {
  5. $niedziala == 'Brak informacji';
  6. }
  7. else
  8. {
  9. $pobierzdane = file_get_contents($link);
  10. }
?

Wolalbym z ifem
Dziekuje ze odpowiedziales
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


if($cos== folse)
a nie false? biggrin.gif


$niedziala == 'Brak informacji';
wystarczy jedno =
Go to the top of the page
+Quote Post
Xander92
post
Post #5





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 1.09.2013

Ostrzeżenie: (0%)
-----


get_headers() [function.get-headers]: Filename cannot be empty
Go to the top of the page
+Quote Post
com
post
Post #6





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


  1. $file = 'http://strona.pl/lind_do_pliku.xml';
  2. $file_headers = @get_headers($file);
  3. if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
  4. $niedziala = 'Brak informacji';
  5. }
  6. else
  7. {
  8. $pobierzdane = file_get_contents($file);
  9. }
  10.  


Ten post edytował com 12.12.2013, 14:49:03
Go to the top of the page
+Quote Post
Xander92
post
Post #7





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 1.09.2013

Ostrzeżenie: (0%)
-----


file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Nieznany host.
Go to the top of the page
+Quote Post
com
post
Post #8





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

Ostrzeżenie: (0%)
-----


http://stackoverflow.com/questions/3797596...ddrinfo-failure
Go to the top of the page
+Quote Post
Xander92
post
Post #9





Grupa: Zarejestrowani
Postów: 32
Pomógł: 0
Dołączył: 1.09.2013

Ostrzeżenie: (0%)
-----


pokaze do czego zmierzam

  1. $file= 'http://steamcommunity.com/groups/poland/memberslistxml/?xml=1.xml';
  2. $file_headers = @get_headers($file);
  3. if($file_headers[0] == 'HTTP/1.1 404 Not Found')
  4. {
  5. $brak = 'Brak';
  6. }
  7. else
  8. {
  9. $get = file_get_contents($file);
  10. }


I chodzi o to ze nie raz ta strona ma "zawieszenia" i chce wtedy wyswietlic brak
i jak nie czyta pliku
to zazwyczaj jest taki komunikat
http://steamcommunity.com/groups/poddfland...txml/?xml=1.xml
spedjalnie wpisalem cos do poland

Ten post edytował Xander92 12.12.2013, 15:38:35
Go to the top of the page
+Quote Post
fate
post
Post #10





Grupa: Zarejestrowani
Postów: 824
Pomógł: 106
Dołączył: 14.03.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Jezeli chcesz wykryc konkretnie czy pojawia sie ta strona to np.
http://at2.php.net/manual/en/domdocument.g...tsbytagname.php

wykryj czy naglowek H1 zawiera: Niestety!


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 11:16