user1046246
user1046246

Reputation: 35

Parse Date from String

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?

Upvotes: 0

Views: 173

Answers (1)

ioseb
ioseb

Reputation: 16941

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);

Upvotes: 1

Related Questions