0

I am using DOMxPath to retrieve the data inside of an element from an xml file...

$xml = file_get_contents('data.xml');
$dom = new DOMDocument();
@$dom->loadHTML($xml);
$domx = new DOMXPath($dom);
$entries = $domx->evaluate("//observation_time");


$arr = array();
foreach ($entries as $entry) {

  $ar6 = $entry->nodeValue;

}


echo "$ar6";

}

here is the xml

<observation_time>Last Updated on Dec 1 2011, 6:47 pm EST</observation_time>

the output is: Last Updated on Dec 1 2011, 6:47 pm EST

My question is: How do i pull only the date out of this string? using find?

1 Answer 1

1

With this input you can do something like this:

$time = 'Last Updated on Dec 1 2011, 6:47 pm EST';

#following line will give you date part only
$time = preg_replace('~^Last Updated on\s*~i', '', $time);

#this line will convert time to unix timestamp
$time = strtotime($time);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.