这是我尝试过的示例
<?php
include 'spider/classes/simple_html_dom.php';
$html = new simple_html_dom();
$html->load("<html><body><h2>Heading 1</h2><h2>This heading 2</h2></p></p></body></html>");
$e = $html->find("h2", 0);
$key = array();
if($e->plaintext != ""){
foreach($html->find("h2", 0) as $e){
//echo $e->plaintext;
array_push($key, $e->plaintext);
}
} else {
echo "error";
}
print_r($key);
?>
结果:
数组( [0] => [1] => [2] => [3] => [4] => [5] => 标题 1 这个标题 2
[6] => [7] => )
如何使用 array_push 创建数组?