i wanted to write an alias for the printf function which automaticly puts a br and a newline on the end of the line.
either it has to work like this:
<code>
function my_printf () {
printf (
do_something_important(func_get_args())
);
echo "<br>\n";
}
// so the line:
my_printf ("Hello World. Today it's the %d.!", (int)date("d"));
// will have the output line:
// Hello World. Today it's the 25.!<br>\n
</code>
but i have no idea how to convert the argument-array to use it again as parameter-list for the printf function.
so the do_something_important function has to split the array in the single arguments and put it in the right format ...
i know that this would work in C because i've tried it. but i wonder how it works in php
or it hast to work with a kind of makro ... i look forward to any kind of solution
second question:
is there any algorythm to calculate the week number out of a date?
thanks and sorry for my bad english =)
bye
parameter list and their problems
Moderator: General Moderators
you might want to take a look at func_num_args, func_get_arg and especially func_get_args
and for the second question getdate
and for the second question getdate
He already knows how to get the arguments, but the problem is passing those arguments to printf().
Here's a neat trick. Use eval(), like this:
All right! Post #100
Here's a neat trick. Use eval(), like this:
Code: Select all
<?php
function my_printf()
{
$args = func_get_args();
$num_args = count($args);
$arg_list = '';
for ($x = 0; $x < $num_args; $x++)
{
if ($x) $arg_list .= ', ';
$arg_list .= "\$argsї$x]";
}
eval("printf($arg_list);");
echo "<br>\n";
}
my_printf ("Hello World. Today it's the %d.!", date("w") + 1);
?>ok thanks about the parameter list problem
but the date("W") is not the right solution for my problem because it returns the week number of the current week.
but what if i want to know the week number of the 15th of august in 1984?
so i need a function which gets a date as parameter and returns the week number
for an example:
$week_nr = date_week_nr ("1984-08-15");
week_nr will have the week number of the week where the 15th of august was in 1984 ...
hope you know what i mean
but the date("W") is not the right solution for my problem because it returns the week number of the current week.
but what if i want to know the week number of the 15th of august in 1984?
so i need a function which gets a date as parameter and returns the week number
for an example:
$week_nr = date_week_nr ("1984-08-15");
week_nr will have the week number of the week where the 15th of august was in 1984 ...
hope you know what i mean
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Why don't you have a look at PHP's date and time functions:
http://www.php.net/manual/en/ref.datetime.php
and perhaps read about date() so that you can make it do what you want:
http://www.php.net/manual/en/function.date.php
Mac
http://www.php.net/manual/en/ref.datetime.php
and perhaps read about date() so that you can make it do what you want:
http://www.php.net/manual/en/function.date.php
Mac
Any date can be used if you pass a "timestamp" to the date() function:
If you have a date in the form "1984-08-15", use strtotime() to convert the string to a timestamp.
(Note: A capitol 'W' won't work. It means "week number of year." Use a small case 'w')
Code: Select all
date("w", $timestamp)Code: Select all
date("w", strtotime("1984-08-15"))