Page 1 of 1

% within a string?

Posted: Mon Mar 25, 2013 5:54 pm
by Pazuzu156
I was working with the DateTime thing, and found that a % allows me to display the date values in a string. Example:

Code: Select all

return $interval->format('%a days ago');
Without the % it returns "a days ago"

What exactly is the % doing, as I've never used it within a string except for when doing a respective output.

Re: % within a string?

Posted: Mon Mar 25, 2013 6:09 pm
by requinix
DateInterval::format

It's a placeholder. That particular function looks for them and substitutes in the appropriate values. Same idea behind strftime() and date() (though the latter doesn't need %s).

Re: % within a string?

Posted: Mon Mar 25, 2013 6:12 pm
by Pazuzu156
Thanks, that's helpful and good to know.