Several to get all the hyperlink address codes in an HTML string

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags address ajax codes function get html javascript string

Several to get all the hyperlink address codes in an HTML string

$ss = "<a href= ' 1.gif ' >d</a>adfxx<a href=" dir.html ">dir</a>";

Print_r (Gethref ($SS));

function Gethref ($temp) {
Preg_match_all ('/<a.*: |t|r|n)? href=[' "]? +?) ['"]? (:(?: |t|r|n) +.*? > (. +?) </a.*?>/sim ', $temp, $a);
return $a [1];
}

All a connections below

$htm = Preg_replace ("@<a" (. *?) </a> @is "," $ ", $ss);
Print_r ($htm);

Compare full extract URL connection address

$url = "http://www.jzread.com";
$html =file_get_contents ($url, "R");
Preg_match_all ("/(<a) (. *) (href=) ([^>]*) (>) ([^<]*] (<) ([^>]*) (>)/", $html, $matches);
For ($i =0 $i <count ($matches [0]); $i + +)
{
echo "| | |" $matches [2][$i]. $matches [3][$i]. $matches [4][$i]. "| |" $matches [6][$i]. $matches [8][$i]. " <br> ";
}//extract all linked addresses in the article string

Preg_match_all ('/(? <=href= ') [wd.:/] * *, $STR, $FSTR);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.