Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]preg_match_all
666
post
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 19.12.2008

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


Witam
Mam taki oto kod
CODE

<a href="http://domena.pl/index.php?option=com_registration&amp;task=lostPassword">
Lost Password?</a>

Chce wyciągnąć z niego tylko czyli to wszystko co jest za domena.pl a przed ">
CODE

index.php?option=com_registration&amp;task=lostPassword

Jak to zrobić napisałem coś takiego ale nie działa
  1. <?php
  2. preg_match_all('(<a href="http://?[^/]+(.+?)">Lost Password?</a>)', $ret, $match);
  3. $arr = $match[1];
  4. print_r($arr);
  5. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
dk1342
post
Post #2





Grupa: Zarejestrowani
Postów: 275
Pomógł: 9
Dołączył: 24.07.2008
Skąd: Racibórz

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


  1. <?php
  2. $string = '<a href="http://domena.pl/index.php?option=com_registration&amp;task=lostPassword">Lost Password?</a>';
  3. preg_match_all('/<a href="http://domena.pl/(.*)">Lost Password?/', $string, $match);
  4. echo $match[1][0]; // index.php?option=com_registration&task=lostPassword
  5. ?>


--------------------
Firefox - The Best,
Internet Exokier - shit

Go to the top of the page
+Quote Post
1010
post
Post #3





Grupa: Zarejestrowani
Postów: 749
Pomógł: 37
Dołączył: 3.10.2006

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


parse_url" title="Zobacz w manualu PHP" target="_manual

  1. <?
  2.  
  3. $url = parse_url($twoj_link);
  4.  
  5. $url2 = $url[path].$url[query];
  6.  
  7. ?>


--------------------
Go to the top of the page
+Quote Post
666
post
Post #4





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 19.12.2008

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


Co do dk1342 to kod chodzi ale tylko jak jest na lokalu .Jak już muszę się połączyć ze strona to kod przestaje działać. Oto kod
  1. <?php
  2. $q ="domena.pl/";
  3. $useragent  = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0';
  4. $ch = curl_init();
  5.  
  6.    curl_setopt($ch, CURLOPT_URL, $q);
  7.    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
  8.    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9.    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  10.      $wynik= curl_exec($ch);
  11.      curl_close($ch);
  12.      //$wynik = '<tr>
  13.        //<td>
  14.        //    <a href="http://domena.pl/index.php?option=com_registration&amp;task=lostPassword">
  15.  
  16.        //        Lost Password?</a>
  17.    //    </td>
  18.    //</tr>
  19. //';
  20.  
  21.  
  22. preg_match_all('/<a href="http://domena.pl/(.*)">
  23.  
  24.                Lost Password?/', $wynik, $match);
  25. echo $match[1][0];
  26. ?>

A co do parse_url to nie moze byc bo adres jest niepełny ucina np amp w adresie
Go to the top of the page
+Quote Post
zegarek84
post
Post #5





Grupa: Zarejestrowani
Postów: 1 332
Pomógł: 294
Dołączył: 12.10.2008
Skąd: Olkusz

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


Kod
<?php
preg_match_all('/<a href="http:\/\/domena.pl\/([^"]*)">.*?Lost Password\?/is', $string, $match);
echo $match[1][0];
?>

i upewnij się czy na stronie w kodzie adres jest aby na pewno w podwójnym cudzysłowiu a nie w pojedyńczym - sprawdź to w operze bo mozilla prawie zawsze pokazuje podwójny nawet jeśli jest pojedyńczy....

Ten post edytował zegarek84 19.04.2009, 07:58:18


--------------------
Jeśli twoja ręka rusza do przodu powstrzymaj swój gniew; gdy wyprzedza cię twój gniew - wycofaj rękę.

Go to the top of the page
+Quote Post
666
post
Post #6





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 19.12.2008

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


Działa dzięki
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 Aktualny czas: 19.08.2025 - 06:28