Find a simple PHP regular match.

Source: Internet
Author: User
Find a simple PHP regular match.
 
 
 
  • [Anime colleagues] Pokemon Black... text 22nd... 2826/18/0 Ding 13-08-29
  • [Youth campus] Snow float in those years... the text is sincere. .. 202/5/0 renasha 13-08-29


In the above code, I only want the URL in the same format. How to write this regular expression.






I wrote the following,
$ Html = file_get_contents ($ setting ['Book _ url']);
$ K = '/
    ';
    $ K. = '(. *) (. *) <\/a> (.*)';
    $ K. = '<\/ul>/isu ';
    Preg_match_all ($ k, $ html, $ rs );
    No matching address


    Reply to discussion (solution)

    Preg_match_all ('#(.*?) <\/A> # I ', $ html, $ rs );

    Write it directly.
    #(.*)#

     
      
      
    • [Anime colleagues] Pokemon Black... text 22nd... 2826/18/0 Ding 13-08-29
    • [Youth campus] Snow float in those years... the text is sincere. .. 202/5/0 renasha 13-08-29


    In the above code, I only want the URL in the same format. How to write this regular expression.






    I wrote the following,
    $ Html = file_get_contents ($ setting ['Book _ url']);
    $ K = '/
      ';
      $ K. = '(. *) (. *) <\/a> (.*)';
      $ K. = '<\/ul>/isu ';
      Preg_match_all ($ k, $ html, $ rs );
      No matching address
      Of course, your regular expression is '/
        (. *) (. *) <\/A> (. *) <\/ul>/isU'
          * Does not match the line break, but the html code
            There are several spaces and line breaks behind
            If you want to obtain ul in class = "main_con", we recommend that you use jquery for processing. It provides a variety of selectors, class selectors, and attribute selectors...

            Test. php
            $ Str = <




            • [Anime colleagues]


              Pokemon Black...


              Body 22nd...





              2826/18/0

              Ding
              13-08-29



            • [Youth campus]


              That year the snow floated...


              The text is sincere...





              202/5/0

              Renasha
              13-08-29


            • Html;

              $ Pattern = "/
              Preg_match_all ($ pattern, $ str, $ matches );
              Var_dump ($ matches [1]);
              ?>
              $ Matches [1] is the url array you want

              #(.*)#

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.