Discussion:
Newbie needs recommendation for fast learning a little php.
(too old to reply)
N***@example.net
2021-06-29 14:30:35 UTC
Permalink
I don't even know if I'm up to the level of being a newbie at this
point. I mostly need to do a specific thing, get a html file to
display its last modified date and time inside itself.

I'm not sure a book is going to be that useful, but maybe a Web site
could be. I'd need one that really is basic.

I've found a Web page or two, but they seem to assume that I know more
than I do because I can't get the code snippets I've found on those
Web pages to work.

I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off. I'm hoping
that php will solve my problem. Thanks in advance.
J.O. Aho
2021-06-29 19:01:57 UTC
Permalink
I mostly need to do a specific thing, get a file to
display its last modified date and time inside itself.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off.
I'm assuming you got the PHP code to work to show the date (even if it's
the wrong timezone for you).

If you have stored the date in a variable $lastmodified then you could
use the following code to adjust it:

$date = date_create($lastmodified, timezone_open('Pacific/Nauru'));
echo date_format($date, 'Y-m-d H:i:sP');

Just use a valid timezone name to replace the Pacific/Nauru. Keep in
mind that the time may look off for other users who do not live in the
timezone you want to display.

For more information about datetime and timezone check the following
page at php.net:

https://www.php.net/manual/en/datetime.settimezone.php
--
//Aho
N***@example.net
2021-06-30 09:58:22 UTC
Permalink
Post by J.O. Aho
I mostly need to do a specific thing, get a file to
display its last modified date and time inside itself.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off.
I'm assuming you got the PHP code to work to show the date (even if it's
the wrong timezone for you).
Yeah, I think.

I used this code:

<p>Date/Time: YYYY-MM-DD hh:mm<br>
<?php echo(strftime("%Y-%m-%d %H:%M")); ?></p>

and it produced this output:

Date/Time: YYYY-MM-DD hh:mm
2021-06-30 05:38

So the above output is the format I want, and it is in my time zone. I
was able to make it so that PHP uses my time zone, even though the
server is far away. What I'll want is the actual date/time string, and
I figure that I can cut out the other part that's before it.

I've been spending a lot of time trying to figure this all out. Right
now I'm thinking that using something like "filemtime" is going to
give me what I want. So far I am not having any luck with it though.

What I need to do is get the PHP script, when I can hammer it out,
into a HTML file and have the file display its own modification time.
Post by J.O. Aho
If you have stored the date in a variable $lastmodified then you could
$date = date_create($lastmodified, timezone_open('Pacific/Nauru'));
echo date_format($date, 'Y-m-d H:i:sP');
Just use a valid timezone name to replace the Pacific/Nauru. Keep in
mind that the time may look off for other users who do not live in the
timezone you want to display.
For more information about datetime and timezone check the following
https://www.php.net/manual/en/datetime.settimezone.php
Yes, I've looked at that and I have the server using my time zone for
PHP output. Thanks for that and thanks for replying.
N***@example.net
2021-06-30 12:08:04 UTC
Permalink
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?

<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>

I feel as if I'm almost there.
Arno Welzel
2021-06-30 13:09:57 UTC
Permalink
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
Why this?
Post by N***@example.net
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
Much simpler:

<?php
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
?>

Also see:

<https://www.php.net/manual/en/reserved.variables.server.php>

"'SCRIPT_FILENAME'

The absolute pathname of the currently executing script."
--
Arno Welzel
https://arnowelzel.de
N***@example.net
2021-06-30 17:46:35 UTC
Permalink
Post by Arno Welzel
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
Why this?
Why the one below here? I'm casting about trying to find something
that works. I'm picking up what I can. I'm pretty much flailing about
at this point.
Post by Arno Welzel
Post by N***@example.net
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
<?php
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
?>
Thanks for that. I've plugged this in and saved it as foo.php and I
get an odd reaction. The actual time stamp on the file is 13:22, but
the above script is telling me that the file was last modified at
13:06. I suppose that the idiots at my Web host may have screwed up
something on the server. The 13:22 time is when I created the file, so
it can't be that it's showing when it was created and not when it was
modified. I'm scratching my head here.
Post by Arno Welzel
<https://www.php.net/manual/en/reserved.variables.server.php>
"'SCRIPT_FILENAME'
The absolute pathname of the currently executing script."
Okay, I don't understand what you mean in the piece immediately above
this. The above url seems to say that the script will just run.
Arno Welzel
2021-07-01 08:49:18 UTC
Permalink
[...]
Post by N***@example.net
Post by Arno Welzel
<?php
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
?>
Thanks for that. I've plugged this in and saved it as foo.php and I
get an odd reaction. The actual time stamp on the file is 13:22, but
the above script is telling me that the file was last modified at
13:06. I suppose that the idiots at my Web host may have screwed up
something on the server. The 13:22 time is when I created the file, so
it can't be that it's showing when it was created and not when it was
modified. I'm scratching my head here.
You can also try this to make sure the file system cache is emptied:

<?php
clearstatcache($_SERVER["SCRIPT_FILENAME"]);
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
?>

And if this doesn't work, use a global cache clear:

<?php
clearstatcache();
echo "This file was last modified on: ";
echo date("Y-m-d H:m",filemtime($_SERVER["SCRIPT_FILENAME"]));
?>

Also see: <https://www.php.net/manual/en/function.clearstatcache.php>
Post by N***@example.net
Post by Arno Welzel
<https://www.php.net/manual/en/reserved.variables.server.php>
"'SCRIPT_FILENAME'
The absolute pathname of the currently executing script."
Okay, I don't understand what you mean in the piece immediately above
this. The above url seems to say that the script will just run.
$_SERVER is a super global array which provides a number of runtime
parameters of the current script. $_SERVER["SCRIPT_FILENAME"] contains
the complete name of the current script including the path or the name
which was passed at command line when using PHP as CLI.
--
Arno Welzel
https://arnowelzel.de
J.O. Aho
2021-06-30 14:24:38 UTC
Permalink
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)

1. Make the webserver to send .html files to tne php engine as it does
with the .php files.

2. Rename the .html file to .php
--
//Aho
N***@example.net
2021-06-30 17:49:13 UTC
Permalink
Post by J.O. Aho
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
J.O. Aho
2021-06-30 20:23:32 UTC
Permalink
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).

It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.

So this leads to the only thing you can do, rename your files so that
they are called .php instead of .html/.htm.

If you don't want to rename files, then you need to look at javascript
solution for displaying last modified document time.
--
//Aho
N***@example.net
2021-07-01 04:49:58 UTC
Permalink
Post by J.O. Aho
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?

Also, some scripts seem to work in html files and some don't.

The following is the entire code for a file I named hello_1.html

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>

It produced the result:

"Hello World

'; ?> "

in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.

Attempts to get the php script I actually want to use to run in an
html file have not, so far, produced the thing the php script tries to
do or else the file doesn't produce any result at all.
Post by J.O. Aho
So this leads to the only thing you can do, rename your files so that
they are called .php instead of .html/.htm.
Yeah, that would be a hassle, but if I can't get the php scripts to
run in html files that may be what I'll have to do. I'd need to see
how those php files would interact with the many html files they link
to.
Post by J.O. Aho
If you don't want to rename files, then you need to look at javascript
solution for displaying last modified document time.
I whipped up a javascript to do what I want days ago, but a lot of
people keep javascript turned off, so it wouldn't work for them. I
supposed I could figure out how to get some message put in place of
the file modification date if javascript is turned off.

Thanks for your help.
J.O. Aho
2021-07-01 06:03:23 UTC
Permalink
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
Also, some scripts seem to work in html files and some don't.
The following is the entire code for a file I named hello_1.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
"Hello World
'; ?> "
in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.
No, it's your web browsers html engine that detects a faulty html tag
with another html tag and tries it best to correct the html and shows
you what it thinks should be shown.

Had you written:

<?php echo 1+1; ?>

your output had been:


yes, nothing at all, and that is the proof of that the php code do not
be executed, had the php engine processed the page before sent to you,
you would have had a 2.
Post by N***@example.net
Attempts to get the php script I actually want to use to run in an
html file have not, so far, produced the thing the php script tries to
do or else the file doesn't produce any result at all.
As long it's in a file ending with html/htm it will not be executed, so
matter what you write, nothing will happen, you need to change the
ending to php.
Post by N***@example.net
Post by J.O. Aho
So this leads to the only thing you can do, rename your files so that
they are called .php instead of .html/.htm.
Yeah, that would be a hassle, but if I can't get the php scripts to
run in html files that may be what I'll have to do. I'd need to see
how those php files would interact with the many html files they link
to.
You just need to change the links to the new page name that ends with
.php and that's it.
Post by N***@example.net
Post by J.O. Aho
If you don't want to rename files, then you need to look at javascript
solution for displaying last modified document time.
I whipped up a javascript to do what I want days ago, but a lot of
people keep javascript turned off, so it wouldn't work for them. I
supposed I could figure out how to get some message put in place of
the file modification date if javascript is turned off.
Itnernet is nowadays quite useless without javascript, so people tend to
not disable it anymore. The benefit with the javascript is that you can
display time the file was modified based on the users timezone.
--
//Aho
Arno Welzel
2021-07-01 10:35:29 UTC
Permalink
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
Also, some scripts seem to work in html files and some don't.
The following is the entire code for a file I named hello_1.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
"Hello World
'; ?> "
in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.
No. The output comes from the fact, that PHP was *not* interpreted.

The browser displays *exactly* this:

<?php echo '<p>Hello World</p>'; ?>

Just have a look at the source of the page which is displayed by the
browser.

Since <?php will treated by the browser as the beginning of a tag, it
will be omitted in the visible output. But "; ?>" is clearly left over
as the PHP code was *not* interpreted but just sent to the browser. The
result is then what you see.

If renaming everything from .html to .php you should look for a hosting
service which allows using .html with PHP as well. Technically this is
just a configuration in the webserver - however that is usually not
possible in shared hosting environments.
--
Arno Welzel
https://arnowelzel.de
N***@example.net
2021-07-02 22:21:10 UTC
Permalink
Post by Arno Welzel
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
Post by J.O. Aho
Post by N***@example.net
This does what I want, but only as a .PHP file. How do I get it into a
file named foo.html so I can have foo.html declare when it was last
modified?
<?php
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
//echo $pfile;
echo "This file was last modified on: " .date("Y-m-d
H:m",filemtime($pfile));
?>
I feel as if I'm almost there.
I won't comment on the code as Arno already done that, there is two
options, I would say one option is not up to you, so in reality you have
only one option (the last one)
1. Make the webserver to send .html files to tne php engine as it does
with the .php files.
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
The issue is that the web server will not treat each file it handles as
a php code, it will only look for files that ends with php, send those
to a PHP-engine which parses the file and executes the php code and then
hands back the output to the web server which then sends the output to
the end user (the visitor to your web page).
It's possible to allow .html/.htm files the same way, but then you need
the administration rights of the server, as you are using a shared
service, it means you don't have administrator privileges and those you
can't do the change.
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
Also, some scripts seem to work in html files and some don't.
The following is the entire code for a file I named hello_1.html
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
"Hello World
'; ?> "
in the browser. It's obviously got a little problem in the output, but
it did produce a mostly useful output.
No. The output comes from the fact, that PHP was *not* interpreted.
<?php echo '<p>Hello World</p>'; ?>
Just have a look at the source of the page which is displayed by the
browser.
Since <?php will treated by the browser as the beginning of a tag, it
will be omitted in the visible output. But "; ?>" is clearly left over
as the PHP code was *not* interpreted but just sent to the browser. The
result is then what you see.
If renaming everything from .html to .php you should look for a hosting
service which allows using .html with PHP as well. Technically this is
just a configuration in the webserver - however that is usually not
possible in shared hosting environments.
It is possible that I have gotten the magic words into the .htaccess
file and I think that I'm able to run PHP scripts from within HTML
files. Even so, I am thinking that I've really been going about this
the wrong way. I may need to learn how to inject HTML into PHP rather
than the other way around, which I've been trying to do.

Anyway, I cobbled together the following code after I seem to have
gotten the server to execute PHP inside every HTML file.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>will php run in html now?</title>
<meta http-equiv="description" content="">
<meta http-equiv="keywords" content=",">
<meta http-equiv="distribution" content="global">
<meta http-equiv="resource-type" content="document">

</head>
<body>

<h1>Am I Going To Get it Now?</h1>

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>

<br>
<br>
Updated:
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
echo "" .date("Y-m-d H:m",filemtime($pfile));
?>

The output of that code was:

Am I Going To Get it Now?

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Updated: 2021-07-02 18:07

That mostly looks okay. I have more to say on it, but I think I'll do
that in a separate post for reasons which I think will become obvious.
N***@example.net
2021-07-02 23:36:09 UTC
Permalink
All right, here's a weird part.

After this code and output
Post by N***@example.net
....
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>will php run in html now?</title>
<meta http-equiv="description" content="">
<meta http-equiv="keywords" content=",">
<meta http-equiv="distribution" content="global">
<meta http-equiv="resource-type" content="document">
</head>
<body>
<h1>Am I Going To Get it Now?</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
<br>
<br>
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
echo "" .date("Y-m-d H:m",filemtime($pfile));
?>
Am I Going To Get it Now?
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Updated: 2021-07-02 18:07
....
No matter what I do I always get the same minutes. The hour changes,
but the minutes are staying the same. I changed the file a bit, and
saved it again and again but the "07" stayed. So right now the string
says the file was modified at 2021-07-02 19:07 even though it's later
than that by a lot and this happened in the previous hour as well.

This can't be something wrong with the code, can it? I think it must
be something wrong with the server. I just know that when I bring this
up to my Web host they're going to say it's the code that's at fault.
Is that possible?

Anyone have an opinion on this?
John-Paul Stewart
2021-07-03 00:01:13 UTC
Permalink
Post by N***@example.net
Post by N***@example.net
echo "" .date("Y-m-d H:m",filemtime($pfile));
No matter what I do I always get the same minutes.
You're not showing minutes at all. Lower case m is month number (as you
used in the date). You probably want H:i for hour and minutes; hour
and month is an odd pairing!

https://www.php.net/manual/en/datetime.format.php
N***@example.net
2021-07-03 04:08:18 UTC
Permalink
On Fri, 2 Jul 2021 20:01:13 -0400, John-Paul Stewart
Post by John-Paul Stewart
Post by N***@example.net
Post by N***@example.net
echo "" .date("Y-m-d H:m",filemtime($pfile));
No matter what I do I always get the same minutes.
You're not showing minutes at all. Lower case m is month number (as you
used in the date).
D'oh! I'm going back and forth so much here that I missed that
entirely. Thanks a lot for pointing out my error.
Post by John-Paul Stewart
You probably want H:i for hour and minutes; hour
and month is an odd pairing!
Yes, the page gives the right modification time now. Thanks a lot.
Post by John-Paul Stewart
https://www.php.net/manual/en/datetime.format.php
Arno Welzel
2021-07-03 13:40:33 UTC
Permalink
***@example.net:

[...]
Post by N***@example.net
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
The function name is "explode()" in lower case and not "Explode()". Even
if PHP accepts the upper case version as well you should use the correct
case to avoid problems with future updates.

Also see: <https://www.php.net/manual/en/function.explode.php>
--
Arno Welzel
https://arnowelzel.de
N***@example.net
2021-07-03 18:36:11 UTC
Permalink
Post by Arno Welzel
[...]
Post by N***@example.net
<?php
date_default_timezone_set('America/New_York');
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
The function name is "explode()" in lower case and not "Explode()". Even
if PHP accepts the upper case version as well you should use the correct
case to avoid problems with future updates.
Okay, thanks. I've corrected that now.
Post by Arno Welzel
Also see: <https://www.php.net/manual/en/function.explode.php>
Pierre Jelenc
2021-07-01 21:36:05 UTC
Permalink
Post by N***@example.net
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
You don't need to control the server itself; many hosts --indeed all the
good ones, I say-- allow you to redirect .html to the PHP engine one way
or another, typically from .htaccess with AddType and AddHandler
directives. Check your host's help system or file a support ticket, they
probably have a FAQ answer ready.

Pierre
--
Pierre Jelenc
The Gigometer www.gigometer.com
The NYC Beer Guide www.nycbeer.org
N***@example.net
2021-07-02 22:49:49 UTC
Permalink
Post by Pierre Jelenc
Post by N***@example.net
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
You don't need to control the server itself; many hosts --indeed all the
good ones, I say-- allow you to redirect .html to the PHP engine one way
or another, typically from .htaccess with AddType and AddHandler
directives. Check your host's help system or file a support ticket, they
probably have a FAQ answer ready.
I have apparently gotten the server to process PHP scripts inside the
HTML file. Things is, that's kind of wasteful and may slow things
down, for me and for others. I did read on one of the many Web pages
I've been looking at over this topic that besides putting "AddType
application/x-httpd-php .html" into my .htaccess file, and making ALL
HTML files get processed for any PHP scripts, that there was also a
way to do it for a single file. I have about five files I need to do
this modification notice for.

The code for a single file that I saw was "<Files yourpage.html>
AddType application/x-httpd-php .html </Files>" where yourpage.html
was whatever that one file was named.

Does anyone know if it's possible to use that declaration, or
something like it, in the .htaccess file so that only the five HTML
files that really need to have PHP processed will get processed and
all other HTML files will not be?
Pierre Jelenc
2021-07-02 23:02:53 UTC
Permalink
Post by N***@example.net
Post by Pierre Jelenc
Post by N***@example.net
Thanks for clarifying that. I don't control the server, but I've read
that those who do can allow html files to be scanned for php code.
Maybe my Web host has in fact done that. Would I be able to find some
notation about that in the Web host's phpinfo.php file?
You don't need to control the server itself; many hosts --indeed all the
good ones, I say-- allow you to redirect .html to the PHP engine one way
or another, typically from .htaccess with AddType and AddHandler
directives. Check your host's help system or file a support ticket, they
probably have a FAQ answer ready.
I have apparently gotten the server to process PHP scripts inside the
HTML file. Things is, that's kind of wasteful and may slow things
down, for me and for others. I did read on one of the many Web pages
I've been looking at over this topic that besides putting "AddType
application/x-httpd-php .html" into my .htaccess file, and making ALL
HTML files get processed for any PHP scripts, that there was also a
way to do it for a single file. I have about five files I need to do
this modification notice for.
The code for a single file that I saw was "<Files yourpage.html>
AddType application/x-httpd-php .html </Files>" where yourpage.html
was whatever that one file was named.
Does anyone know if it's possible to use that declaration, or
something like it, in the .htaccess file so that only the five HTML
files that really need to have PHP processed will get processed and
all other HTML files will not be?
It should work (but again, it depends on the way the server is set up).
Alternatively, rename the relevant files to .htm and redirect .htm to PHP
but leave .html alone.

Pierre
--
Pierre Jelenc
The Gigometer www.gigometer.com
The NYC Beer Guide www.nycbeer.org
😉 Good Guy 😉
2021-07-01 21:53:35 UTC
Permalink
In accordance with the rules of 21st century technology, the main message is posted in HTML format. Some people may not be able to read it in any of the non-mozilla newsreaders. For them I give them my customary two fingers salute and send my FO greetings.
--
With over 1.3 billion devices now running Windows 10, customer
satisfaction is higher than any previous version of windows.
Arno Welzel
2021-07-01 10:29:17 UTC
Permalink
[...]
Post by N***@example.net
Post by J.O. Aho
2. Rename the .html file to .php
Uh oh. But I'm reading that I can embed php into a html file. Isn't
that possible?
It is - but the file must be processed by PHP. This usually does not
happen, when the file exension is ".html".
--
Arno Welzel
https://arnowelzel.de
Ray_Net
2021-06-30 21:03:22 UTC
Permalink
Post by N***@example.net
I don't even know if I'm up to the level of being a newbie at this
point. I mostly need to do a specific thing, get a html file to
display its last modified date and time inside itself.
I'm not sure a book is going to be that useful, but maybe a Web site
could be. I'd need one that really is basic.
I've found a Web page or two, but they seem to assume that I know more
than I do because I can't get the code snippets I've found on those
Web pages to work.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off. I'm hoping
that php will solve my problem. Thanks in advance.
https://code.adonline.id.au/last-modified-date-php/
N***@example.net
2021-07-02 22:07:50 UTC
Permalink
On Wed, 30 Jun 2021 23:03:22 +0200, Ray_Net
Post by Ray_Net
Post by N***@example.net
I don't even know if I'm up to the level of being a newbie at this
point. I mostly need to do a specific thing, get a html file to
display its last modified date and time inside itself.
I'm not sure a book is going to be that useful, but maybe a Web site
could be. I'd need one that really is basic.
I've found a Web page or two, but they seem to assume that I know more
than I do because I can't get the code snippets I've found on those
Web pages to work.
I used to use ssi for this, but I moved to a new Web host and they
seem to have their server time zone set as the only time zone I can
display, and they are far away from me, so in ssi I get a date and
time for a file modification time that's many hours off. I'm hoping
that php will solve my problem. Thanks in advance.
https://code.adonline.id.au/last-modified-date-php/
I had been looking around for days and I didn't run across that Web
page. Wish I'd seen it sooner, although I don't know yet if it's going
to solve my problems. Thanks for that link.
Blue Hat
2021-08-08 18:43:20 UTC
Permalink
I don't even know if I'm up to the level of being a newbie at thispoint. I mostly need to do a specific thing, get a html file todisplay its last modified date and time inside itself.I'm not sure a book is going to be that useful, but maybe a Web sitecould be. I'd need one that really is basic.I've found a Web page or two, but they seem to assume that I know morethan I do because I can't get the code snippets I've found on thoseWeb pages to work.I used to use ssi for this, but I moved to a new Web host and theyseem to have their server time zone set as the only time zone I candisplay, and they are far away from me, so in ssi I get a date andtime for a file modification time that's many hours off. I'm hopingthat php will solve my problem. Thanks in advance.
--
Have you tried setting up your own webserver to try this out on?
Try doing basic stuff and work your way up to figuring it out? I
had messaged similar problem with using JS in PHP and although my
solution wasn't too elegant it did what I wanted.


The point is to break down what u want done and attack each step.
Next, use HTML in your file to do what you want to then replace
each one with a PHP snippet. I could offer you some help if you
would like.


----Android NewsGroup Reader----
https://piaohong.s3-us-west-2.amazonaws.com/usenet/index.html
Loading...