loadHTML($html); $nodes = $doc->getElementsByTagName('title'); $title = $nodes->item(0)->nodeValue; $description = ""; $keywords = ""; $image = ""; $metas = $doc->getElementsByTagName('meta'); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if($meta->getAttribute('name') == 'description') $description = $meta->getAttribute('content'); if($meta->getAttribute('name') == 'keywords') $keywords = $meta->getAttribute('content'); if($meta->getAttribute('property')=='og:image'){ $image = $meta->getAttribute('content'); } } return [ 'image' => $image, 'title' => $title, 'description' => $description ]; } $url = get_url(); $url_params = parse_url($url); if (!$url) { exit(0); } $html = file_get_contents_curl($url); $result = get_meta_from_html($html); $result = array_merge( get_meta_from_html($html), array( 'linkUrl' => $url, 'linkText' => $url_params["host"] . isset($url_params["path"])?$url_params["path"]:"", ) ); echo json_encode($result); ?>