Return to Snippet

Revision: 15285
at June 30, 2009 01:46 by cshaiku


Initial Code
function extract_urls($data)
{
  $links = array();
  $pos = (int) 0;
  $i   = (int) 0;

  while (!(($pos = strpos($data,"<a",$pos)) === false)) {
    $startpos = strpos($data,"\"", $pos);
    $endpos = strpos($data,"\">",$pos);
    $tag = trim(substr($data,$startpos+1,($endpos-$startpos-1)));
    $tag = substr($tag, 0, strlen($tag));
    $end_tag_pos = strpos($data,'</a>',$endpos);
    $linked_text = strip_tags(substr($data, $endpos+2, ($end_tag_pos-$endpos-2)));
    $links[$i][0] = stripslashes($linked_text);
    $links[$i][1] = stripslashes($tag);
    $pos++;
    $i++;
  }
  return $links;
}

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

Initial Description

                                

Initial Title
Extract URLs From HTML

Initial Tags
url, html, array, links

Initial Language
PHP