Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> document.links w php (DOM)
Dex1987
post 15.01.2007, 16:50:51
Post #1





Grupa: Zarejestrowani
Postów: 246
Pomógł: 0
Dołączył: 28.09.2004

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


Witam,

probuje zrobić w php funkcje działającą tak samo jak document.links (JS). Szukałem na pl.php.net/dom jakiegoś odpowiednika, ale nie widziałem niczego podobnego, probowałem coś kombinować z getAtribute, ale nie wchodziło mi to. Czy jest w ogóle możliwe zrobienie czegoś takiego tylko w php, jeśli tak to proszę o jakieś nakierowanie.

Pozdrawiam.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
ActivePlayer
post 15.01.2007, 19:07:19
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 224
Pomógł: 40
Dołączył: 6.07.2004
Skąd: Wuppertal

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


moze zawierac bugi:
  1. <?php
  2. function get_links_from_href($string, $from_site){
  3. if(!$string || !$from_site)return;
  4. $end=array();
  5. $end['url_inside']=0;
  6. $end['url_outside']=0;
  7. $url=parse_url($from_site);
  8. $url['dir']=preg_replace("|^(.*)/.*..*$|i","1",$url['path']);
  9. preg_match_all("/<a href=["']{1}(.*?)["']{1}/i",$string,$links);
  10. for($o=0;$o<count($links[1]);$o++){
  11. if($links[1][$o] && !ereg("^(java script:|gg:|mailto:)",$links[1][$o])){
  12.  
  13. if(ereg("^?",$links[1][$o]))$links[1][$o]="http://".$url['host'].$url['path'].$links[1][$o];
  14. if(!ereg("^http://",$links[1][$o])){
  15. $links[1][$o]="http://".$url['host'].(!ereg("^/",$links[1][$o])?(!ereg("/$",$url['dir'])?$url['dir']."/":$url['dir']):(ereg("/$",$url['dir'])?substr($url['dir'],0,-1):$url['dir'])).$links[1][$o];
  16. $end['url_inside']++;
  17. }else{$end['url_outside']++;}
  18. $end[]=$links[1][$o];
  19. }
  20. }
  21.  
  22. return $end;
  23. }
  24. ?>


jako $string podajesz źródło strony, jako $from_site jej adres.
Go to the top of the page
+Quote Post

Posty w temacie


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 - 19:26