Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] wyrażenia regularne
marcinek37
post 17.06.2013, 10:12:05
Post #1





Grupa: Zarejestrowani
Postów: 239
Pomógł: 0
Dołączył: 2.06.2011

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


jak sprawdzić, czy w danym stringu jest podany adres strony www?
problem w tym, że adres strony może być podany na kilka sposobów:
- http://www.onet.pl
- http://www.onet.pl/
- www.onet.pl
- www.onet.pl/
- onet.pl
- onet.pl/

i w dodatku zamiast .pl może być .com, .com.pl, .net i wiele innych
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
ssstrz
post 17.06.2013, 10:24:15
Post #2





Grupa: Zarejestrowani
Postów: 103
Pomógł: 17
Dołączył: 15.12.2012

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


http://kohanaframework.org/3.3/guide-api/Valid#url w metodzie url jest pattern, wywal sobie to co w sekcji #scheme i masz sprawdzanie adresu bez protokolu np http://

edit// sorki z pospiechy nie zauwarzylem 2 pierwszych linkow z http, w takim razie nic nie modyfikuj tylko przekopiuj sobie metode url

Ten post edytował ssstrz 17.06.2013, 11:01:19
Go to the top of the page
+Quote Post
marcinek37
post 17.06.2013, 11:52:21
Post #3





Grupa: Zarejestrowani
Postów: 239
Pomógł: 0
Dołączył: 2.06.2011

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


ta funkcja jest bardzo przydatna, ale nie o to mi chodziło

chodzi o to, że mam ciąg znaków i chcę sprawdzić, czy jest w nim link, np.
aaaaaaaaaa bbbbbbbbbbbbbb onet.pl ccccccccccccccc dddddddddddddd

i chcę, aby skrypt zdiagnozował, że jest tam podany link
Go to the top of the page
+Quote Post
nospor
post 17.06.2013, 11:53:58
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




preg_match


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
marcinek37
post 17.06.2013, 12:25:09
Post #5





Grupa: Zarejestrowani
Postów: 239
Pomógł: 0
Dołączył: 2.06.2011

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


znam tę funkcję, ale nie potrafię napisać tego tak, aby skrypt znajdywał linki w tekście, no i linki w kilku formatach
Go to the top of the page
+Quote Post
ssstrz
post 17.06.2013, 12:59:53
Post #6





Grupa: Zarejestrowani
Postów: 103
Pomógł: 17
Dołączył: 15.12.2012

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


ok w temacie pytałeś o inny przypadek, bo chciałeś sprawdzanie urla a teraz nagle chcesz "wyłowić urla"...... no ale przetestuj to
  1. // The Regular Expression filter
  2. $reg_exUrl = "/((http|https|ftp|ftps)\:\/\/)?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  3.  
  4. // The Text you want to filter for urls
  5. $text = "The text you want to filter goes here. http://google.com";
  6.  
  7. // Check if there is a url in the text
  8. if(preg_match($reg_exUrl, $text, $url)) {
  9.  
  10. // make the urls hyper links
  11. echo $url[0];
  12.  
  13. } else {
  14.  
  15. // if no urls in the text just return the text
  16. echo $text;
  17.  
  18. }

przerobione stąd: http://css-tricks.com/snippets/php/find-ur...ext-make-links/

Ten post edytował ssstrz 17.06.2013, 13:05:27
Go to the top of the page
+Quote Post
marcinek37
post 17.06.2013, 14:14:53
Post #7





Grupa: Zarejestrowani
Postów: 239
Pomógł: 0
Dołączył: 2.06.2011

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


Twój kod działa dokładnie tak, jak chciałem
Bardzo dziękuję!
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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:28