How to deal with regular expression matching

Source: Internet
Author: User
Tags preg
Regular expression match to match this format with regular expression & lt; LI & gt; & lt; A & nbsp; href = "http://news.17173.com/" & nbsp; target = _ blank & gt; news Center & lt;/A & gt; & nbsp; & lt ;? Php & nbsp regular expression matching
You want to use a regular expression to match this format.
  • News Center




      
    $con= file_get_contents("http://17173.com");
      
    $preg = '#
  • (.*)#';
      
    preg_match_all($preg, $con, $arr); 
      
    //print_r($arr[1]);
      
    foreach($arr[1] as $id=>$v){
      
      echo "".$v." ".$arr[2][$id]."
    ";
        
    }
      
    ?>



  • There is no matching result, but there is a link in this format on this page.
    ------ Solution --------------------
    First, target = "_ blank" does not match the one given above. which one is it?

    Then echo $ con.

    Determine expected content
    Pay attention to the case sensitivity and line feed issues-your regular expression is fixed with case sensitivity, and the dot does not contain line breaks.
    ------ Solution --------------------
    Preg_match_all ('/
  • (.*?) <\/A>/I ', $ str, $ matches );
    Var_dump ($ matches [1]);

    Your problem is that the content of your website is like target = _ blank, but your target = "_ blank" is like this. if you have more quotation marks, you cannot match them.
  • 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.