Re: Newbie needs recommendation for fast learning a little php.

[email protected] Fri, 02 Jul 2021 18:21:10 -0400
Newsgroups comp.lang.php,alt.comp.lang.php,alt.php
Organization Newshosting.com - Highest quality at a great price! www.newshosting.com
Message-ID <[email protected]>
On Thu, 1 Jul 2021 12:35:29 +0200, Arno Welzel <[email protected]>
wrote:

>[email protected]:
>
>> On Wed, 30 Jun 2021 22:23:32 +0200, "J.O. Aho" <[email protected]>
>> wrote:
>> 
>>>
>>> On 30/06/2021 19.49, [email protected] wrote:
>>>> On Wed, 30 Jun 2021 16:24:38 +0200, "J.O. Aho" <[email protected]>
>>>> wrote:
>>>>
>>>>> On 30/06/2021 14.08, [email protected] wrote:
>>>>>> 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.
>
>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.

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.