Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [regexp]Wyciaganie URLi
tnkywe
post 13.07.2006, 20:09:35
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 2.08.2005

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


Witam,
Moglby ktos podrzucic fragment skryptu php ktory wycigalby wszystkie urle (nie mowie tylko o linkach w <a> ) z danej zmiennej?
Probowalem bawic sie z preg_match_all ale nie bylem w stanie napisac zadnej odpowiedniej regulki sad.gif Z gory dzieki za wszelkiego rodzaju sugestie.

Pozdrawiam,
Marcin
Go to the top of the page
+Quote Post
treewood
post 13.07.2006, 21:55:20
Post #2





Grupa: Zarejestrowani
Postów: 215
Pomógł: 0
Dołączył: 18.01.2003

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


nie wiem czy to to co ci trzeba ale przyjzyj sie lepiej komentarzom do tej funkcji o ktorej pisales: http://pl.php.net/manual/pl/function.preg-match-all.php


--------------------
Działam w OpenSolution.org, autor Quick.Cms i Quick.Cart już od ponad 10 lat
Go to the top of the page
+Quote Post
tnkywe
post 13.07.2006, 23:01:27
Post #3





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 2.08.2005

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


Przejrzelem juz wczesniej. narazie mam 2 takie fragmenty kodu ale zadnen nie zwraca tego co powinien:
Kod
$html='aaaaaaa http://to.jest.adres.com/test.html?zmienna=1 aaaaaaa';

preg_match_all("/(http[s]?):\/\/{1}([\w\.-]+)\.(\w{2,6}){1}/", $html, $matches);
print_r($matches);

preg_match_all('/(http|https):\/\/([^:\/\s]+)((\/\w+)*)(([\w\-\.]+\.[^#?\s]+)(.*?)(#[\w\-]+)?)?/',$html,$matches);
print_r($matches);


Zwraca:
Kod
Array
(
    [0] => Array
        (
            [0] => http://to.jest.adres.com
        )

    [1] => Array
        (
            [0] => http
        )

    [2] => Array
        (
            [0] => to.jest.adres
        )

    [3] => Array
        (
            [0] => com
        )

)
Array
(
    [0] => Array
        (
            [0] => http://to.jest.adres.com/test
        )

    [1] => Array
        (
            [0] => http
        )

    [2] => Array
        (
            [0] => to.jest.adres.com
        )

    [3] => Array
        (
            [0] => /test
        )

    [4] => Array
        (
            [0] => /test
        )

    [5] => Array
        (
            [0] =>
        )

    [6] => Array
        (
            [0] =>
        )

    [7] => Array
        (
            [0] =>
        )

    [8] => Array
        (
            [0] =>
        )

)
Go to the top of the page
+Quote Post
siemakuba
post 14.07.2006, 01:05:22
Post #4





Grupa: Przyjaciele php.pl
Postów: 1 112
Pomógł: 20
Dołączył: 10.04.2005

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


Kod
$html=' aaaaaaa http://to.jest.adres.com/test.html?zmienna=1 aaaaaaa http://www.wp.pl i potem jeszcze https://www.secure.com';
preg_match_all('/\s(https?:\/\/\S*)/si', $html, $m);
print_r($m);


wynik:
Kod
Array
(
    [0] => Array
        (
            [0] =>  http://to.jest.adres.com/test.html?zmienna=1
            [1] =>  http://www.wp.pl
            [2] =>  https://www.secure.com
        )

    [1] => Array
        (
            [0] => http://to.jest.adres.com/test.html?zmienna=1
            [1] => http://www.wp.pl
            [2] => https://www.secure.com
        )
)


pozdr.

Ten post edytował siemakuba 14.07.2006, 01:06:56
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: 20.07.2025 - 01:33