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 #169974 is a reply to message #169968] Sat, 02 October 2010 14:11 Go to previous messageGo to previous message
Rob is currently offline  Rob
Messages: 5
Registered: October 2010
Karma:
Junior Member
<?php

function _format_date ($op, $days) {
echo $op . $days . ' day';
echo '<br />';
$str = "$op$days day";
echo $str;
echo '<br />';
return ($str);
// $date = new DateTime ();
// $date -> modify ($op . $days . ' day');
// return ($date -> format ('Y-m-d'));
}

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

$letter_subs = array (
'/\{\{DATE([+\-])(\d{1,3})\}\}/i' => _format_date ('\1', '\2'),
);

$parsed_letter = preg_replace (array_keys ($letter_subs), array_values
($letter_subs), $letter);

echo $parsed_letter;

?>

The above (assuming it came through unmolested) returns:

\1\2 day
\1\2 day
Please respond by +10 day.

Because I pulled this out of a larger application that's echoing the
parsed letter, I always tested using return rather than echo. Seeing
the \1\2 being echoed now leads me to assume that what's being passed
to the aren't actual backreference results, but instead the literal
\1\2 strings, which explains 1) why date->modify fails, and 2) why I
saw it as returning the correct information.

So, I guess my question changes from why isn't the date conversion
working to "How can I get the actual backreference results passed to a
function?"
[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 13:47:57 GMT 2024

Total time taken to generate the page: 0.04354 seconds