Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> 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
bendi
post
Post #2





Grupa: Zarejestrowani
Postów: 401
Pomógł: 5
Dołączył: 14.09.2003
Skąd: Wrocław

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


zapomniales o https:// smile.gif


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





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

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: 21.08.2025 - 12:15