% within a string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

% within a string?

Post 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.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: % within a string?

Post 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).
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

Re: % within a string?

Post by Pazuzu156 »

Thanks, that's helpful and good to know.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Post Reply