1

I want to load content of a specific div with class='box' from a webpage, and I used Simple HTML DOM for this. but I can't write a clear pattern for preg_match, here is my php code:

<?php
   $url = "http://www.example.com/pages/";
   $page_all = file_get_contents($url); 

   preg_match(...?);


   echo "<pre>";
   print_r($div_array[0]);
   echo "</pre>";
?>

Please help me to write a right pattern for preg_match

4

2 回答 2

2

SimpleHtmlDOM :

$html = new simple_html_dom();

// Load from a string
$html->load('<html><body><p>Hello World!</p><p>We're here</p></body></html>');

// Load a file
$html->load_file('http://net.tutsplus.com/');

# get an element representing the second paragraph  
$element = $html->find("div[class=box1]");

#access HTML attr
$element->innertext .= "Somthing";

#save and echo
echo $element->save();
于 2012-02-06T06:42:08.570 回答
1

You should check out: http://simplehtmldom.sourceforge.net/

An example would be:

$html = new simple_html_dom();

$html = file_get_html('http://www.example.com/pages/');

$ret = $html->find('div[class=box]');

Don't waste your time with Regex, there are tools for the job.

于 2012-02-06T06:32:50.663 回答