2

私は SimpleXMLElement を次のように使用しています:

$visitor_body = wp_remote_retrieve_body( $url );
$visitor_data = new SimpleXMLElement( $visitor_body );

次の XML 構造の応答があります。

<resultSet>
  <aggregates>
     <metric name="visitDuration" value="488" label="Avg. Visit Duration"/>
     <metric name="uniqueVisitors" value="8" label="Unique Visitors"/>
     <metric name="visits" value="14" label="Visits"/>
     <metric name="pageViews" value="35" label="Page Views"/>
     <metric name="bounceRate" value="0.5" label="Bounce Rate"/>
     <metric name="pagesPerVisit" value="2.5" label="Pages Per Visit"/>
  </aggregates>

などの値をvisitDuration uniqueVisitors visitsいろいろなところで使えるように取得する必要があります。たとえば、次のような変数内で:

echo $visitDuration;
echo $uniqueVisitors;
4

1 に答える 1

1

http://php.net/manual/en/book.simplexml.php - このページは調査が必要な場所です。

またはこれはどうですか?

http://simplehtmldom.sourceforge.net/

* A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
* Require PHP 5+.
* Supports invalid HTML.
* Find tags on an HTML page with selectors just like jQuery.
* Extract contents from HTML in a single line.

// Find all visitDuration
foreach($html->find('visitDuration') as $element)
       echo $element->value. '<br>'; // returns 488

// Find all bounceRate
foreach($html->find('bounceRate') as $element)
       echo $element->value. '<br>'; // returns 0.5
于 2012-11-24T05:24:34.737 に答える