Page 1 of 1 [ 9 posts ] 

AspieBaby
Butterfly
Butterfly

User avatar

Joined: 11 Jul 2012
Gender: Female
Posts: 12

22 Feb 2013, 9:49 am

Can someone help me with this??

First, using today’s date, convert it into a variable.

Example: if today is 18th Sept 2009

It will be 18092009

Next, using this variable, add up all the individual numbers until it become a single digit.

Example: 18092009 will be 1+8+0+9+2+0+0+9 = 29 then 2+9 = 11 then 1+1 = 2

Next, using that single digit, convert 6 occurrences of that digit into a string and add a '#' in front of it.

Example: #222222

Finally, output a string using the previous converted string as the bgcolor for this body tag. This should be the only string your codes will be outputting.

Example: <body bgcolor="#222222"></body>

Using PHP, program the above solution.

I have tried but I can't >.<
Please help me...



Trencher93
Velociraptor
Velociraptor

User avatar

Joined: 23 Jun 2008
Age: 124
Gender: Male
Posts: 464

22 Feb 2013, 11:59 am

This sounds like another homework assignment. If you know the answer, do this person a favor and don't post it. He'll learn more figuring it out himself. Hints: strftime() and division are the tools you need.



AspieBaby
Butterfly
Butterfly

User avatar

Joined: 11 Jul 2012
Gender: Female
Posts: 12

22 Feb 2013, 10:06 pm

Trencher93 wrote:
This sounds like another homework assignment. If you know the answer, do this person a favor and don't post it. He'll learn more figuring it out himself. Hints: strftime() and division are the tools you need.


Nono... I am trying too....

is it like this?

<?php
$first = 'd';
$second = 'm';
$third = 'Y';
?>

This is today's date: <?php echo date('dmY'); ?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>
<?php echo('d'); ?>+<?php echo('m'); ?>+<?php echo('Y'); ?></p>

<?php

?>



rickith
Raven
Raven

User avatar

Joined: 29 Apr 2009
Age: 35
Gender: Male
Posts: 122
Location: The Netherlands

23 Feb 2013, 5:48 am

Remember that code outside of PHP context does not get executed, so <?php date('d'); ?>+<?php date('m'); ?>+<?php date('Y'); ?> will just display 23 + 2 + 2013 in your browser.

This (if done in PHP context) also doesn't quite get you what you want because PHP would add the results of each date call to the other, resulting in 23 + 2 + 2013 = 2038, it doesn't sum up the individual digits.

What you want to do is store the result of date('dmY') in a variable and then find a way to loop through each of the digits and sum them up. This process will then have to be repeated untill the sum is < 10. There's serveral ways to do this, Trencher93 has given you a good hint for one solution.



AspieBaby
Butterfly
Butterfly

User avatar

Joined: 11 Jul 2012
Gender: Female
Posts: 12

23 Feb 2013, 10:09 am

I understand!! !^^
I will share with you once I finished^^



AspieBaby
Butterfly
Butterfly

User avatar

Joined: 11 Jul 2012
Gender: Female
Posts: 12

24 Feb 2013, 1:47 am

http://naomi.astrobunny.net/ifounderies/date.php

Can you see??

[Mod. edit: removed redundant "img" tags because a php page is not an image file]



rickith
Raven
Raven

User avatar

Joined: 29 Apr 2009
Age: 35
Gender: Male
Posts: 122
Location: The Netherlands

24 Feb 2013, 9:41 am

Nope, doesn't seem to work for me (I get a 500 page). Perhaps you can just post your PHP code here, that way we'll be able to see how you've done it and perhaps give you some feedback.



KonTrax
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 20 May 2012
Age: 35
Gender: Female
Posts: 51

25 Feb 2013, 9:50 am

Just a lazy example but its something. Wrote it for fun so be aware of possible bad code

Quote:
// Function
function string2singleInt( $string )
{
$total = 0;
if( strlen($string) > 1 ){
$intList = str_split($string);
for($i=0, $count=count($intList); $i < $count; $i++){
$total += $intList[$i];
}
}
return strlen($total) > 1 ? string2singleInt($total) : $total;
}

// Use
$number = string2singleInt( 18092009 );
$hex = '#'.$number.$number.$number.$number.$number.$number;
echo 'bgcolor="'.$hex.'"';



rickith
Raven
Raven

User avatar

Joined: 29 Apr 2009
Age: 35
Gender: Male
Posts: 122
Location: The Netherlands

02 Mar 2013, 11:10 am

AspieBaby wrote:
http://naomi.astrobunny.net/ifounderies/date.php

Can you see??



Did you manage to figure it out?