Posted By

cshaiku on 06/30/09


Tagged

url html array links


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

cshaiku
rickfu
irishsk
BrianCoyDesign


Extract URLs From HTML


 / Published in: PHP
 

URL: http://code.cshaiku.com/code_php_extract_urls.php

  1. function extract_urls($data)
  2. {
  3. $links = array();
  4. $pos = (int) 0;
  5. $i = (int) 0;
  6.  
  7. while (!(($pos = strpos($data,"<a",$pos)) === false)) {
  8. $startpos = strpos($data,"\"", $pos);
  9. $endpos = strpos($data,"\">",$pos);
  10. $tag = trim(substr($data,$startpos+1,($endpos-$startpos-1)));
  11. $tag = substr($tag, 0, strlen($tag));
  12. $end_tag_pos = strpos($data,'</a>',$endpos);
  13. $linked_text = strip_tags(substr($data, $endpos+2, ($end_tag_pos-$endpos-2)));
  14. $links[$i][0] = stripslashes($linked_text);
  15. $links[$i][1] = stripslashes($tag);
  16. $pos++;
  17. $i++;
  18. }
  19. return $links;
  20. }

Report this snippet  

You need to login to post a comment.