Extract URLs From HTML


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.