Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Poprawność adresu URL ..., ... jak sprawdzić?
id4
post
Post #1





Grupa: Zarejestrowani
Postów: 223
Pomógł: 1
Dołączył: --
Skąd: Rogożnik /K-ce/

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


Witam

Jak za pomocą wyrażeń regularnych sprawdzić poprawność wpisanego adresu url?
Adres może mieć postać 'http://', 'www.' lub 'http://www.'.
Poprawny adres może być też adresem IP.

Ten post edytował id4 29.03.2005, 14:54:26
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
markac
post
Post #2





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 23.02.2005

Ostrzeżenie: (10%)
X----


  1. <?php
  2. function is_url( $url )
  3. {
  4.  if ( !( $parts = @parse_url( $url ) ) )
  5. return false;
  6.  else {
  7.  if ( $parts[scheme] != &#092;"http\" && $parts[scheme] != \"https\" && $parts[scheme] != \"ftp\" && $parts[scheme] != \"gopher\" )
  8. return false;
  9.  else if ( !eregi( &#092;"^[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,4}$\", $parts[host], $regs ) )
  10. return false;
  11.  else if ( !eregi( &#092;"^([0-9a-z-]|[_])*$\", $parts[user], $regs ) )
  12. return false;
  13.  else if ( !eregi( &#092;"^([0-9a-z-]|[_])*$\", $parts[pass], $regs ) )
  14. return false;
  15.  else if ( !eregi( &#092;"^[0-9a-z/_.@~-]*$\", $parts[path], $regs ) )
  16. return false;
  17.  else if ( !eregi( &#092;"^[0-9a-z?&=#,]*$\", $parts[query], $regs ) )
  18. return false;
  19.  }
  20.  return true;
  21. }
  22. ?>
Go to the top of the page
+Quote Post

Posty w temacie
- id4   Poprawność adresu URL ...   29.03.2005, 14:51:28
- - bendi   zapomniales o https://   29.03.2005, 15:08:31
- - markac   [PHP] pobierz, plaintext <?php function is_url...   29.03.2005, 15:23:23


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: 2.10.2025 - 08:36