Re: Problems modifying date using regex [message #169968 is a reply to message #169962] |
Sat, 02 October 2010 09:20 |
Captain Paralytic
Messages: 204 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Oct 2, 3:23 am, Rob <rbutle...@gmail.com> wrote:
> I've (yet again) run into an issue with PHP that makes me question my
> sanity.
>
> I have a number of form letters available that include an option for
> modifying the date contained within. For example, a letter may
> reference a future date like "Please respond by {{DATE+10}}.", and a
> past date could be "{{DATE-10}}".
>
> I've got a regex that pulls the relevant information out of the letter
> ('/\{\{DATE([+\-])(\d{1,3})\}\}/i'), which tells me that I need to
> eitheradd or subtract days. I'm passing \1 and \2 to a function which
> appears verbatim below:
>
> function _format_date ($op, $days) {
> $date = new DateTime ();
> $date -> modify ($op . $days . ' day');
> return ($date -> format ('Y-m-d'));
>
> }
>
> Given the example showing exactly this operation at php.net (http://
> us.php.net/manual/en/datetime.modify.php), one would expect it to
> work. Unfortunately, it simply returns the current date.
>
> I've verified that \1 and \2 are correctly being passed to the
> function as $op and $days. I've tried casting the vars with no
> difference. I've tried encasing them in a string ("$op$days day"), and
> assigning the string to a separate variable. In all cases, it returns
> the current date without modification and acts as though $op and $days
> are null.
>
> I've verified that simply using the string "+10 day" works as
> expected, but there seems to be something special about using the
> values from a regex that causes this to fail.
>
> Please help!
Can you post the call as well?
|
|
|