Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Wyciąganie URL-a
adam882
post
Post #1





Grupa: Zarejestrowani
Postów: 289
Pomógł: 1
Dołączył: 2.11.2007

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


Witam

Posiadam przykładowo taki link:
http://www.strona.pl/dom/remonty/firma-remontowa.html

W jaki sposób można z tego linka wyciągnąć jedynie adres URL (http://www.strona.pl) ?
Go to the top of the page
+Quote Post
mortus
post
Post #2





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Np. wyrażeniem regularnym:
  1. $pattern = '#^(http://.*?)/#si';
  2. $url = 'http://www.strona.pl/dom/remonty/firma-remontowa.html';
  3. preg_match($pattern, $url, $matches);
  4. echo $matches[1];

lub za pomocą substr() i strpos():
  1. $url = 'http://www.strona.pl/dom/remonty/firma-remontowa.html';
  2. $address = substr($url, 0, strpos($url, '/', 8)-1);
  3. echo $address;


Ten post edytował mortus 20.12.2011, 09:02:16
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: 15.09.2025 - 04:14