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 #169968 is a reply to message #169962] Sat, 02 October 2010 09:20 Go to previous messageGo to previous message
Captain Paralytic is currently offline  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?
[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: Wed Nov 27 05:59:01 GMT 2024

Total time taken to generate the page: 0.04455 seconds