use php code to echo all the <timestamp></timestamp> from xml

Getting a list of forms

$res = Formstack::request('ABCDE', 'forms');


The PHP client also allows for a more OOP approach:

$formstack = new Formstack('ABCDE');
$res = $formstack->forms();


The PHP client uses serialized PHP as the data format; this means that the returned data is a native PHP array. The following code will loop through the forms that were returned in the above calls:

foreach($res['forms'] as $form) {
    print "{$form['id']} -  {$form['name']}\n";
}


Retrieving Data

$res = Formstack('ABCDE', 'data', array('id' => 111, encryption_password => 'foobar'));


The OOP approach:

$formstack = new Formstack('ABCDE');
$res = $formstack->data(111, array('encryption_password' => 'foobar'));


Looping through the submissions:

foreach($res['submissions'] as $submission) {
    ...
}






the output is in xml



<?xml version="1.0" encoding="utf-8"?>
<response status="ok">
<submissions>
<submission>
<id>1001</id>
<timestamp>2007-01-01 01:01:01</timestamp>
<user_agent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)</user_agent>
<remote_addr>127.0.0.1</remote_addr>
<data>
<item>
<field>1111</field>
<value>John Smith</value>
</item>
<item>
<field>2222</field>
<value>Apple</value>
</item>
</data>
</submission>
<submission>
<id>1001</id>
<timestamp>2007-02-02 02:02:02</timestamp>
<user_agent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)</user_agent>
<remote_addr>127.0.0.1</remote_addr>
<data>
<item>
<field>1111</field>
<value>Jane Smith</value>
</item>
<item>
<field>2222</field>
<value>Banana</value>
</item>
</data>
</submission>
</submissions>
<total>2</total>
<pages>1</pages>
</response>


use php code to echo all the <timestamp></timestamp> from xml
<?php
/**
 * Copyright (c) 2010 Formstack, LLC
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @copyright 2010 Formstack, LLC
 * @license   http://www.opensource.org/licenses/mit-license.php
 * @link      http://www.Formstack.com/api.html
 */

class Formstack {

    private static $api_url = 'https://www.formstack.com/api';
    
    private $api_key = null;

    public function __construct($api_key) {

        $this->api_key = $api_key;
    }

    /**
     * Returns a list of forms in an account. The response includes all of the
     * information returned by the form method, with the exception of
     * information about each form field and the HTML or JavaScript required to
     * display the form.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=23
     * @return array
     */
    public function forms() {

        return self::request($this->api_key, 'forms', array());
    }

    /**
     * Returns detailed information about a form.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=24
     * @param  mixed $id form id
     * @return array
     */
    public function form($id) {

        return self::request($this->api_key, 'form', array('id' => $id));
    }

    /**
     * Returns data collected for a form.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=25
     * @param mixed $id form id
     * @param array $args optional arguments
     * @return array
     */
    public function data($id, $args = array()) {

        $args['id'] = $id;
        return self::request($this->api_key, 'data', $args);
    }

    /**
     * Returns a single submission collected for a form.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=26
     * @param mixed $id form id
     * @param array $args optional arguments
     * @return array
     */
    public function submission($id, $args = array()) {

        $args['id'] = $id;
        return self::request($this->api_key, 'submission', $args);
    }

    /**
     * This method submits data to a form. This method does not honor any
     * validation or default values configured for a field. because of the lack
     * of validation checks, it is not intended for day-to-day use for public
     * submissions. The form must be configured to store submissions in the
     * database. An error will be returned if the maximum number of submissions
     * for the account has been reached.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=27
     * @param mixed $id form id
     * @param array $args optional arguments
     * @return array
     */
    public function submit($id, $args = array()) {

        $args['id'] = $id;
        return self::request($this->api_key, 'submit', $args);
    }

    /**
     * This method makes changes to an existing submission. Only values
     * supplied within the arguments will be overwritten.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=28
     * @param mixed $id submission id
     * @param array $args
     * @return array
     */
    public function edit($id, $args = array()) {

        $args['id'] = $id;
        return self::request($this->api_key, 'submit', $args);
    }

    /**
     * Deletes an existing submission.
     *
     * @link http://support.formstack.com/index.php?pg=kb.page&id=29
     * @param mixed $id submission id
     * @param array $args optional arguments
     * @return array
     */
    public function delete($id, $args = array()) {

        $args['id'] = $id;
        return self::request($this->api_key, 'delete', $args);
    }

    /**
     * Makes a Formstack API call and returns the response as an array.
     *
     * @param string $api_key Formstack API key
     * @param string $method API method
     * @param array $args API arguments
     * @return array
     */
    public static function request($api_key, $method, $args = array()) {

        $args['api_key'] = $api_key;
        $args['type'] = 'php';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, self::$api_url . '/' . $method);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args));
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        $res = curl_exec($ch);
        curl_close($ch);

        if(empty($res)) die("Unexpected Error");

        $php_res = unserialize($res);

        if ($php_res['status'] == 'error')
            die('API Error: '.$php_res['error']);

        return $php_res['response'];
    }
}

?>

Open in new window

LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZShaverCommented:
function get_string_between($string, $start, $end){
      $string = " ".$string;
      $ini = strpos($string,$start);
      if ($ini == 0) return "";
      $ini += strlen($start);
      $len = strpos($string,$end,$ini) - $ini;
      return substr($string,$ini,$len);
}

$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");

$lines = preg_split( '/\r\n|\r|\n/', $xml_string);;
foreach($lines as $line) {
   if(substr_count($line,"<timestamp>") > 0)
     echo(get_string_between($line, "<timestamp>", "</timestamp>"););
}
0
Ray PaseurCommented:
See http://www.laprbass.com/RAY_temp_rgb192.php

Moving parts start on line 50.  Outputs:
2007-01-01 01:01:01
1111 = John Smith
2222 = Apple

2007-02-02 02:02:02
1111 = Jane Smith
2222 = Banana
<?php // RAY_temp_u08.php
error_reporting(E_ALL);
echo "<pre>";


// TEST DATA
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<response status="ok">
<submissions>
<submission>
<id>1001</id>
<timestamp>2007-01-01 01:01:01</timestamp>
<user_agent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)</user_agent>
<remote_addr>127.0.0.1</remote_addr>
<data>
<item>
<field>1111</field>
<value>John Smith</value>
</item>
<item>
<field>2222</field>
<value>Apple</value>
</item>
</data>
</submission>
<submission>
<id>1001</id>
<timestamp>2007-02-02 02:02:02</timestamp>
<user_agent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)</user_agent>
<remote_addr>127.0.0.1</remote_addr>
<data>
<item>
<field>1111</field>
<value>Jane Smith</value>
</item>
<item>
<field>2222</field>
<value>Banana</value>
</item>
</data>
</submission>
</submissions>
<total>2</total>
<pages>1</pages>
</response>
XML;

// MAKE AN OBJECT
$obj = SimpleXML_Load_String($xml);

// ACTIVATE THIS TO SEE THE OBJECT
// var_dump($obj);

// USE AN ITERATOR TO ACCESS THE PROPERTIES OF THE OBJECT
foreach ($obj->submissions->submission as $s)
{
    // SHOW THE TIMESTAMP
    $t = (string)$s->timestamp;
    echo PHP_EOL . $t;

    foreach ($s->data->item as $i)
    {
        // SHOW FIELD AND VALUE PROPERTIES
        $f = $i->field;
        $v = $i->value;
        echo PHP_EOL . "$f = $v";
    }
    echo PHP_EOL;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192Author Commented:
thanks
0
rgb192Author Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.