1. The requirements are as follows:
-sitemap-:http://xxx.xxx/xx.xml
:http://xxx/xxx/xx ()
-xml- title
2. My code looks like this:
set_time_limit(0);
function get_title($url) {
$output = file_get_contents($url);
$page = [];
$page["title"] = "";
preg_match("/<TITLE>([\w\W]*?)<\/TITLE>/si", $output, $m);
$page["title"] = $m[1];
return $page["title"];
}
$xml_str = file_get_contents($xml_url);
// $data = simplexml_load_file($xml_str);
$xml_obj = simplexml_load_string($xml_str);
$data = [];
$current = time();
foreach ($xml_obj as $k => $v) {
$data[$k]["title"] = get_title($v->loc);
$data[$k]["url"] = $v->loc;
$data[$k]["created_at"] = $current;
}
$ret = Sitemap::insert($data);
but this is easy to collapse, and the local service cannot run directly when the data is submitted.
? Is there a better solution