public function classdate(){
$find = \think\Db::table('classa')->field('id,folder,ClassBasicInfo')->select();
$arr = [];
foreach ($find as $key => $value) {
$arr[$key]['url'] = 'http://www.xxx.com/' . $value['folder'];
$arr[$key]['id'] =$value['id'];
}
return $arr;
}
public function curl(){
set_time_limit(0);
$ch = array();
$res = array();
$conn = array();
$html=[];
$urls =$this->classdate();
foreach ($urls as $key => $url) {
$ch = curl_init($url['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$html[$key]['id']= $url['id'];
$html[$key]['title'] = preg_match('!<title>(.*?)</title>!i', $result, $matches) ? $matches[1] : '';
$html[$key]['keywords'] = preg_match('/<META\s+name="keywords"\s+content="([\w\W]*?)"/si', $result, $matches) ? $matches[1] : '';
$html[$key]['desc'] = preg_match('/<META\s+name="description"\s+content="([\w\W]*?)"/si', $result, $matches) ? $matches[1] : '';
$update = \think\Db::table('classa')->where('id', $url['id'])->update([
'title'=>$html[$key]['title'],
'keywords' =>$html[$key]['keywords'],
'desc'=>$html[$key]['desc'],
]);
}
dump($html);
}