JacobHsu
4/13/2016 - 5:49 AM

#app #store #php

#app #store #php

<?php
    $url = 'https://www.microsoft.com/zh-tw/store/apps/facebook/9wzdncrfhv5g';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $html = curl_exec($ch);

    curl_close($ch);

    $data = array();
    $data['name'] = strip_tags(_tag_content($html, '<h1 id="page-title" class="header-small m-v-n srv_title srv_microdata" itemprop="name">', "</h1>"));

    $data['icon'] = _tag_content($html, '<div class="pull-left ph-logo m-r-md">', "</div>");
    preg_match('/<img(.*)src(.*)=(.*)"(.*)"/U', $data['icon'], $result);
    $data['icon'] = array_pop($result);

    $html_metadata = _tag_content($html, '<dl class="metadata-list row">', "</dl>");
    $html_metadata = explode('</dd>',$html_metadata);

    $data['publisher'] = strip_tags(_tag_content($html_metadata[0], '<div class="content m-b-n clamp-5" data-vp1-lines="5" data-vp2-lines="5">', '</div>'));

    $data['tag'] =strip_tags(_tag_content($html_metadata[1], '<div class="content m-b-n clamp-5" data-vp1-lines="5" data-vp2-lines="5">', '</div>'));

    $data['description'] = _tag_content($html, '<p class="content m-b-n has-newline" data-vp1-lines="4" data-vp2-lines="3">', "</p>");

    print_r($data); exit;

    function _tag_content($html, $start, $end)
    {
        $html = str_replace($start, "", strstr($html, $start));
        return strstr($html, $end, true);
    }
?>