Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] URL i wyrażenia regularne
lukasz91
post
Post #1





Grupa: Zarejestrowani
Postów: 149
Pomógł: 7
Dołączył: 6.01.2010
Skąd: Opole Lubelskie

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


Mam taki kod funkcji:
  1. /*
  2.   * It checks if string is an URL.
  3.   *
  4.   * @param string $string
  5.   * @param string $flags
  6.   * Posibility flags:
  7.   * HOST_REQUIRED - URL with a host (example: http://url.com),
  8.   * PATH_REQUIRED - URL with path after a name of domain (example: http://url.com/Home)
  9.   * QUERY_REQUIRED - URL with a Query String (example: http://url.com/index.php?x=y).
  10.   * @return boolean
  11.   */
  12. function isURL($string, $flags='QUERY_REQUIRED') {
  13. if($flags=='HOST_REQUIRED') {
  14. return (bool)preg_match("/^(http|https|ftp|file):\/\/(www)?[a-zA-Z0-9_\/.\-]+\.[a-zA-Z0-9]+(\/)?$/i", $string);
  15. }
  16. else if($flags=='PATH_REQUIRED') {
  17. return (bool)preg_match("/^(http|https|ftp|file):\/\/(www)?[a-zA-Z0-9_\/.\-]+\.[a-zA-Z0-9]+\/[a-zA-Z0-9_.\-#]*$/i", $string);
  18. }
  19. else if($flags=='QUERY_REQUIRED') {
  20. return (bool)preg_match("/^(http|https|ftp|file):\/\/(www)?[a-zA-Z0-9_\/.\-]+\.[a-zA-Z0-9]+\/[a-zA-Z0-9_.\-#]*\?[a-zA-Z0-9_.,\-?#=&]+$/i", $string);
  21. }


W jaki sposób pozbyć się możliwości napisania 2 kropek obok siebie? Prosiłbym również o spr. czy nie ma tu innych błędów. (IMG:style_emoticons/default/smile.gif)

Ten post edytował lukasz91 26.12.2010, 13:53:12
Go to the top of the page
+Quote Post

Posty w temacie


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: 24.08.2025 - 23:08