General Question

lefteh's avatar

How would I perform this operation on a string in PHP?

Asked by lefteh (9424points) January 27th, 2009

So, basically, I have a bunch of data in this form:

When: Tue Feb 10, 2009 7:20am to 8am&nbsp;EST<br>
<br>Who: Author
<br>Where: Place
<br>Event Status: Status <br/>

(It’s a Google Calendar XML file).

And I want to display it with only the title and the date. The title is its own field in the XML file, so that’s fine. But the date is part of a lumped-together “summary” field, which contains the when, the who, the where, and the status. So what I want to do is add something in my PHP loop that will trim down that entire field to just the date. So in the above example, it would print like this:

Feb 10, 2009<br>

What string operations could do this? I wrestled with preg_replace to no avail.

Observing members: 0 Composing members: 0

4 Answers

richardhenry's avatar

That isn’t XML, that’s HTML. Can you not grab the data in a format where times are stamps?

Vinifera7's avatar

You can use regular expressions, but I agree with richard: you shouldn’t have to grab the time data in a stamped format. Otherwise you have to convert it to a more suitable format, which will be significantly more difficult.

Vincentt's avatar

Yeah, from Google Calendar you can get much better output, surely. Also, there’s probably libraries out there that can help you with this (check out the Zend_GData Calendar component of the Zend Framework).

Still, a function that you might be interested in just because it’s intesting is strtotime which can be used in combination with date for normalisation. And the SimpleXML PHP class is very useful for working with XML.

lefteh's avatar

@richardhenry: It’s HTML within the XML file. One of the well-known shortfalls of Google Calendar XML publishing is its lack of a time field in the normal XML file.

However, I just found an alternate XML file that has a more advanced structure, and includes a startTime element. Looks like I won’t have to break into Zend…thanks guys.

Answer this question




to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther