FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problems modifying date using regex
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Problems modifying date using regex [message #169975 is a reply to message #169974] Sat, 02 October 2010 15:43 Go to previous message
Rob is currently offline  Rob
Messages: 5
Registered: October 2010
Karma:
Junior Member
OK, spent a little time after breakfast pondering this, and was able
to come up with a solution:

<?php

function _format_date_callback ($matches) {
$date = new DateTime ();
$date -> modify ($matches[1] . $matches[2] . ' day');
return ($date -> format ('Y-m-d'));
}

$letter = 'Please respond by {{DATE+10}}.';

$date_sub = '/\{\{DATE([+\-])(\d{1,3})\}\}/i';

$parsed_letter = preg_replace_callback ($date_sub,
_format_date_callback, $letter);

echo $parsed_letter;

?>

Now the only remaining issue is to wrap it in a loop to catch all the
possibilities.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Array count for each value in turn syntax?
Next Topic: Frst foray into PHP _SELF
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 10:49:14 GMT 2024

Total time taken to generate the page: 0.04994 seconds