[Include] Date function (php like)
#1

Hey.

I didn't know what title may I give to the topic, so I give this one. If it's not enough explicit, please tell me.
Originally, this function is the product of a game between me and Kilou. He made the base and I just finished it. But because his code was really odd, I remade it "from scratch" (I just kept the beginning).
The include works properly and keeps the PHP syntax.

HOW THIS CAN BE USEFUL ?

If you have ever coded in PHP, this function is the exact replica of the php date function. There are only two differences that will be listed at the end of the post.
This function allows you, by passing "specifiers" (just like sscanf), to get a formatted string returned by the function and which will contain all the data the specifier you passed "adds".

Instead of making a whole list of the specifiers, I just give you the documentation of the function on php.net, which is here : http://www.php.net/manual/en/function.date.php

You can also include special characters which aren't specifiers (such as spaces, '/', '-', '.', ',') in the "format", and control what will happen through the second parameter of the function (block_unk) : this is an optionnal parameter set to false by default.
If it is to false, so if you don't change the parameter, these special characters will be included as they are in the returned string. Else, if it is set to "true", this characters simply won't appear in the returned string.

EXAMPLES OF USAGE

The basic example would be

PHP код:

printf
("%s"date("d/m")); 
Which will print the current day and the current month, including the leading zeros (for example, for today, it will print "20/06").

And a more precise print :

PHP код:

printf
("Now, it's %s !"date("r")); 
Which will print : "Today, it's Fri, 20 Jun 2014 17:40:35".

I don't know if these examples are explicit enough. If they aren't, simply ask.

DIFFERENCES

The two differencies between the original php function and this one are that
• I've not "remade" the functions about timezones, because first using the pawn, I think it's impossible and secondly because if it's possible using GeoIP includes/plugins combined to World Map timezones, I don't have the knwoledge yet (timezone's name, which countries don't use daylight saving time, etc) to do. So if someone has this, it will be very kind to help me about this.
• I've not "remade" the 'o' specifier, because I simply don't see how it can be useful. If someone knows, again, tell me.

HUGE THANKS

Vince : Pointing out a big mistake I've done which stopped the compiler until he told me how to fix it.
Alexis (Chipardeur) : Big help in small debug phases and testing the function (if you want to rep me for this work, I kindly ask you to rep him too, he really deserves it).
Kilou : The basic function, and the challenge.

DOWNLOAD

Source - Pastebin
Ready-to-use include - Solidfiles

NOTE : Sorry if I did some english mistakes, as you could have guessed, English isn't my first language.
Reply
#2

Very well liked, only part of the day can be done independently, but the rest is very beautiful, I really liked the idea as a sscanf.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)