Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Preg_match
vegeta
post
Post #1





Grupa: Zarejestrowani
Postów: 122
Pomógł: 0
Dołączył: 9.11.2008

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


  1. preg_match_all("/<a(?:[^>]*)href=\"(http:\/\/[^\"]*)\"(?:[^>]*)>(?:[^<]*)<\/a>/is", $stripped_file, $matches);


Co mam zrobić, aby wypluwało mi tylko linki do stron głównych? Chodzi mi o to, aby nie wypluwało wyników, które mają kilka / po głównym adresie. Chcę, żeby wyświetlało mi tylko wyniki z jednym / i bez niego np. http://onet.pl i http://onet.pl/, ale nie dawało już http://onet.pl/dzieci_neo albo http://onet.pl/dzieci_neo/blaaa/
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Piogola
post
Post #2





Grupa: Zarejestrowani
Postów: 151
Pomógł: 36
Dołączył: 1.02.2011
Skąd: Warszawa

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


  1. <?php
  2. $original_file = file_get_contents("http://it-maniak.pl/");
  3. $stripped_file = strip_tags($original_file, "<a>");
  4. preg_match_all('#href="(http://[^/]+/)"#is', $stripped_file, $matches);
  5.  
  6. header("Content-type: text/plain");
  7. print_r($matches);
  8. ?>


Kod
Array
(
    [0] => Array
        (

        )    
[1] => Array
        (
            [0] => http://forum.it-maniak.pl/
            [1] => http://debnix.compu.boo.pl/
            [2] => http://forum.it-maniak.pl/
            [3] => http://grajek.it-maniak.pl/
            [4] => http://tcn.cba.pl/
            [5] => http://potterwarta.info/
            [6] => http://evilus.wordpress.com/
            [7] => http://kurshtml.boo.pl/
            [8] => http://mikonews.tk/
            [9] => http://wordpress.org/
            [10] => http://wordpress.org/
        )


)


Ten post edytował Piogola 2.02.2011, 19:40:47
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: 30.12.2025 - 05:27