PHP regex matches the class div in HTML and selects the contents of the method, classdiv_php tutorial

Source: Internet
Author: User

PHP matches the class div in HTML and selects the contents of the method, Classdiv


The example in this paper is a method that PHP matches the div in HTML with class and selects the content. Share to everyone for your reference. The specific analysis is as follows:

Let's take a look at some HTML code:

Copy the Code code as follows:


Tide Table data for reference only
















Tide Time (Hrs)

00:58

05:20

13:28

21:15

High tide (CM)

161

75

288

127


Time zone:-1000 (East 10) Tidal height datum: 174CM at mean sea level





This is part of the source program, in order to be easy to understand, cut a large part, just take the contents of the DIV block

Home first Use file_get_content or curl to get the content part, I use curl.
Copy the Code code as follows: $ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_postfields, $data);
$return = curl_exec ($ch);
Curl_close ($ch);

$regex 4= "/.*?<\/div>/ism";
if (Preg_match_all ($regex 4, $return, $matches)) {
Print_r ($matches);
}else{
echo ' 0 ';
}

This is OK, not much explanation, understand the PHP code, print to see the effect.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/942409.html www.bkjia.com true http://www.bkjia.com/PHPjc/942409.html techarticle PHP matches the class div in HTML and selects the contents of the method, classdiv the example of PHP matches the class Div in the HTML and select the contents of the method. Share to everyone ...

  • 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.