Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Pobieranie ikony strony
e-milnet
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.08.2011

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


W jaki sposób pobrać ikonę strony której podam adres?
Go to the top of the page
+Quote Post
Fifi209
post
Post #2





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

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


Poszukać czy jest fav.ico ew. favicon.ico ;]
Go to the top of the page
+Quote Post
e-milnet
post
Post #3





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.08.2011

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


Znaczy się jak? Bo chodzi mi o to zeby robic dynamicznie odnosniki do stron z ikonami.
Go to the top of the page
+Quote Post
Fifi209
post
Post #4





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

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


W źródle strony sprawdzić czy jest? Jeżeli jest to wyświetlić link?
Go to the top of the page
+Quote Post
e-milnet
post
Post #5





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.08.2011

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


Tak i później przerobił bym to w odnośnik obrazkowy.
Go to the top of the page
+Quote Post
!*!
post
Post #6





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


file_get_contents
preg_match

Ten post edytował !*! 13.09.2011, 17:09:01
Go to the top of the page
+Quote Post
e-milnet
post
Post #7





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.08.2011

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


Jestem słaby w wyrażeniach regularnych więc dalej proszę o pomoc. Swój skrypt doprowadziłem do postaci:
  1. function find_icon_URL($url)
  2. {
  3. $pattern = '^<link rel=\"Shortcut icon\" href=\"+[[:graph:]]+\" />$';
  4. preg_match($pattern ,file_get_contents($url), $table);
  5. $string = $table[0];
  6.  
  7. return $string;
  8. }
Go to the top of the page
+Quote Post
!*!
post
Post #8





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


  1. preg_match("~<(link(.+?)rel=\"(shortcut icon|icon)\"[^>])*>~");
Go to the top of the page
+Quote Post
e-milnet
post
Post #9





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 18.08.2011

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


Wyskakuje mi bład:
Notice: Undefined offset: 0

  1. function find_icon_URL($url)
  2. {
  3. $pattern = "~<(link(.+?)rel=\"(shortcut icon|icon)\"[^>])*>~";
  4. preg_match($pattern ,file_get_contents($url), $table);
  5. $string = $table[0];
  6.  
  7. return $string;
  8. }
Go to the top of the page
+Quote Post
!*!
post
Post #10





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


Bo to tylko teoretyczny przykład był. Zacznijmy od tego że nie każda strona ma w źródle favikonę. Wystarczy że ma plik .ico w głównym katalogu. Pobierz źródło strony, sprawdź czy występuje tag <link> coś w stylu <link (.*)> bo nie zawsze atrybuty będą w tej samej kolejności. A jeśli nie chce Ci się tego pisać to skorzystaj z

http://www.google.com/s2/favicons?domain=forum.php.pl



Ten post edytował !*! 13.09.2011, 18:53:58
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 14.09.2025 - 14:45