[pmwiki-users] php/strftime question

Jon Haupt jhaupt at gmail.com
Thu Sep 21 10:24:52 CDT 2006


On 9/21/06, Patrick R. Michaud <pmichaud at pobox.com> wrote:
>
> On Thu, Sep 21, 2006 at 09:13:03AM -0500, Jon Haupt wrote:
> >    Hi all,
> >
> >    Why doesn't this work:
> >
> >    $blogposttime = 'strftime("%H", $page["ctime"])';
> >    if ($blogposttime == "22") $FmtPV['$BlogTimeOfDay'] = "It was getting
> >    late";
> >
> >    When I try using {$BlogTimeOfDay} in a page, nothing is
> returned.  All I
> >    want to do is have the time of day displayed not in numeric fashion,
> but
> >    using a custom message corresponding to the time of day.  Perhaps I
> >    misunderstood strftime?  Or I have something mixed up?
>
>
> Surely you mean something like:
>
>     $blogposthour = strftime('%H', $page['ctime']);
>     if ($blogposthour == '22') $FmtPV['$BlogTimeOfDay'] = "'It was getting
> late'";
>
> Note especially the single quotes inside of double quotes in the
> $FmtPV value, because $FmtPV is called with eval().
>
> Another way to do this might be to use a lookup array:
>
>    $BlogPostHours = array(7 => 'It was early', 22 => 'It was getting
> late');
>
>    $FmtPV['$BlogTimeOfDay'] =
>     '$GLOBALS["BlogPostHours"][strftime("%H", $page["ctime"])]';
>
> Pm
>

Awesome, thanks.  Unfortunately because %H produces two-digit strings, I had
to use array('07' => 'it was too early'), etc., but this worked.

Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users/attachments/20060921/dbc5899e/attachment.html 


More information about the pmwiki-users mailing list