1

编辑:

我决定完全改变我对你们的看法。我正在使用亚马逊提供的脚本连接到 Alexa API 并获取一些信息。我的数据库中有一个表,我从(通过 URL)提取行并使用此脚本尝试使用此收集的信息更新当前为空白的一些列。

下面的示例显示了我为http://google.com获得的结果

我希望我的措辞是正确的,并且没有太混乱。

以下代码:

public static function parseResponse($response) {
    $xml = new SimpleXMLElement($response,null,false,
                                'http://awis.amazonaws.com/doc/2005-07-11');
    if($xml->count() && $xml->Response->UrlInfoResult->Alexa->count()) {
        $info = $xml->Response->UrlInfoResult->Alexa;
        $nice_array = array(
            'Phone Number'   => $info->ContactInfo->PhoneNumbers->PhoneNumber,
            'Owner Name'     => $info->ContactInfo->OwnerName,
            'Email'          => $info->ContactInfo->Email,
            'Street'         => $info->ContactInfo->PhysicalAddress->Streets->Street,
            'City'           => $info->ContactInfo->PhysicalAddress->City,
            'State'          => $info->ContactInfo->PhysicalAddress->State,
            'Postal Code'    => $info->ContactInfo->PhysicalAddress->PostalCode,
            'Country'        => $info->ContactInfo->PhysicalAddress->Country,
            'Links In Count' => $info->ContentData->LinksInCount,
            'Rank'           => $info->TrafficData->Rank
        );
    }
    echo '<pre>';
    print_r(array_values($nice_array));
    echo '</pre>';
}

会输出这个:

Array
(
    [0] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [1] => SimpleXMLElement Object
        (
            [0] => aa
        )

    [2] => SimpleXMLElement Object
        (
            [0] => dns-admin@google.com
        )

    [3] => SimpleXMLElement Object
        (
            [0] => aa
        )

    [4] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [5] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [6] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [7] => SimpleXMLElement Object
        (
            [0] => unlisted
        )

    [8] => SimpleXMLElement Object
        (
            [0] => 3555997
        )

    [9] => SimpleXMLElement Object
        (
            [0] => 1
        )

)

如您所见,这些“对象”中的每一个都对应于上面的代码,分别显示电话号码、所有者姓名、电子邮件、街道、城市、州、邮政编码、国家、链接计数和排名。

我需要做的是获取每个值并更新数据库中的该行。

4

1 回答 1

0

让 PHP 为您完成工作;

于 2015-10-28T23:20:18.433 回答