Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [regexp]Wyciaganie URLi
tnkywe
post
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 (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) Z gory dzieki za wszelkiego rodzaju sugestie.

Pozdrawiam,
Marcin
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tnkywe
post
Post #2





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

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: 12.10.2025 - 23:26