I am using a XML feed that has a tag [PUBDATE] with the follwing format ex: 29 Jun 09 : 10:12:05
I would like to extract (echo) just the time in this format 10:12.
Can anyone help me with the PHP (5) code?
I have used <?= gmdate("H:i", strtotime($item["PUBDATE"]));?> ... but it prints time 00:00
Thanks.
Joao
Extract time from XML PUBDATE
Moderator: General Moderators
Re: Extract time from XML PUBDATE
The date is literally that?
And this is from an RSS feed? That's stupid. Specifications are meant to be followed, not blindly ignored.
If it always has a space+colon+space and the time is on the far side of it, use explode to split the string into date/time chunks...
Code: Select all
29 Jun 09 : 10:12:05If it always has a space+colon+space and the time is on the far side of it, use explode to split the string into date/time chunks...
Re: Extract time from XML PUBDATE
If you have to, you can parse it out with regex.
Code: Select all
<?php
if (preg_match('#^\d{1,2}\s[a-z]{3,4}\s\d{1,4}\s:\s(\d{1,2}):(\d{1,2}):\d{1,2}$#i', "29 Jun 09 : 10:12:05", $matches)) {
$time = "{$matches[1]}:{$matches[2]}";
} else {
$time = "unknown";
}
echo $time;