Jump to content

Recommended Posts

<html>

 

<head>

 

<title>PHP Assignment</title>

 

</head>

 

<body>

 

<p><b>Part 4</b></p>

 

<font color="red">

 

<?php

 

print date("D F d Y, H:i:s", time());

 

?>

 

</font>

 

<br></br>

 

<?php

 

$d = getdate();

$len = strlen($d);

$n = "";

 

for($x=0; $x<$len; $x++)

{

    $n .= "*";

 

}

 

 

?>

 

</body>

 

</html>

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705279
Share on other sites

Or you could do this:

 

$d = getdate();
$len = strlen($d);
echo str_pad("", $len, "*");

 

I would think that would work. But if you know the amount of characters you could just do:

 

echo str_pad("", 8, "*");

 

If it is always 24 hour time that should be true.

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705285
Share on other sites

Will, the problem is that I need the characters to change with the seconds everytime I reload the PHP code.  Make sense?  This sounds so simple to do.  I missing something...

 

Thanks...

 

No not really.

 

You mean you want to change from ******* to --------- to ^^^^^^^^^ to &&&&&&&& ?

 

Provide an example of what you want written out like output should look like:

******

 

Then the next page load it should look like:

&&&&&&&&

 

And maybe that will clear up what you want.

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705320
Share on other sites

Part 4

Wed December 03 2008, 15:53:32

 

*****

 

<<There should be 32 astericks to correspond with 32 seconds.>>

 

Ahhh now that is much easier to do:

 

$cnt = date("s", getdate());
echo str_pad("", $cnt, "*");

 

That should work as long as getdate() returns a valid date that can be used by the date function.

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705342
Share on other sites

One problem.  The date() function returns the seconds but with the leading zeros.  So, in some cases, you're going to have extra characters. 

 

Should be an easy fix.

 

$cnt = date("s", getdate());
echo str_pad("", intval($cnt), "*");

 

intval should solve that issue.

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705401
Share on other sites

Here's my code again:

 

<html>

 

<head>

 

<title>PHP Assignment</title>

 

</head>

 

<body>

 

<p><b>Part 4</b></p>

 

<font color="red">

 

<?php

 

print date("D F d Y, H:i:s", time());

 

?>

 

</font>

 

<br></br>

 

<?php

 

$cnt = date("s", getdate());

echo str_pad("", intval($cnt), "*");

 

 

?>

 

</body>

 

</html>

 

This is the output:

 

Part 4

 

Wed December 03 2008, 16:56:25

 

*

 

Note:  I'm still not getting the correct amount of astericks with seconds.

 

Please help!!!  Thanks...

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705419
Share on other sites

Alright, I do not think getdate is what you want.  I would  go this route. Also please use [ code ] tags to make code look presentable.

 

<html>

<head>

<title>PHP Assignment</title>

</head>

<body>

<p><b>Part 4</b></p>

<font color="red">

<?php
   $now = time();
   print date("D F d Y, H:i:s", $now);

?>   

</font>

<br></br>

<?php

$cnt = date("s", $now);
echo str_pad("", intval($cnt), "*");

?>

</body>

</html>

 

Assigned the $now to the current time and just using that to reference everything. getdate returns an array of values and you really do not need that. Hopefully the above works.

Link to comment
https://forums.phpfreaks.com/topic/135395-getdate-function/#findComment-705429
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.