Find all the linked PHP code in the page

Source: Internet
Author: User

  1. function Get_links ($link) {
  2. $html = file_get_contents ($link);
  3. $html = Str_replace ("\ n", "", $html);
  4. $html = Preg_replace ('/$html = preg_replace ('/<\/a>/', "\ n", $html);
  5. Preg_match_all ('/.*?<\/a>/', $html, $matches);
  6. return ($matches);
  7. }
Copy Code
In this example, we want to use file_get_contents to get the content of a Web page. Then use Str_replace ("\ n", "", $html) to remove all the line breaks. Then use Preg_replace ('//', ' \ n ', $html) to put all the ... Mode to another line. Finally, the link mode is matched with Preg_match_all ('/.*?<\/a>/', $html, $matches). /.*?<\/a>/is a match ..... The regular expression of this pattern. Then why do we have to put ... Link to another line?? Because in the/.*?<\/a>/mode,. * is not able to match the line-wrapping, so as and not in the same line can not match!! So we're going to do this!
Php
  • 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.