Newbie: PHP output within HTML page

Newbie: PHP output within HTML page

am 08.08.2007 20:00:39 von Tullamore

Hello,

Sorry for the newbie question. I am trying to add some dynamic content to
an existing HTML page. I would like to add a random saying to an area of a
HTML doc. Sort of like a "fortune" - that would display a different fortune
every minute.

I figure that I can write a PHP script to select a random fortune from a
file, but how do I embed that text within a HTML doc.I want to keep the HTML
document just as it is now but add this php text. I don't want to rename
MyHtml.html to MyHtml.php which I can do now.

Is there a way to execute a external php script from within an HTML and have
its return value displayed in the HTML?

Thanks in advance,
bruce

Re: Newbie: PHP output within HTML page

am 08.08.2007 20:15:22 von unknown

Post removed (X-No-Archive: yes)

Re: Newbie: PHP output within HTML page

am 09.08.2007 14:32:45 von dvader

> AddHandler application/x-httpd-php .htm
> AddHandler application/x-httpd-php .html

> You would need to restart Apche again so it rereads the config file, but
should
> get you were you want to go. It would allow you to add PHP content with the
HTML
> pages, so that you don't have to rename all the pages on your site to .php
> files.

It should be noted that passing all the passive HTML pages through the PHP
engine will slow response times and increase work for the server.
--
Crash

Re: Newbie: PHP output within HTML page

am 09.08.2007 20:37:12 von unknown

Post removed (X-No-Archive: yes)

Re: Newbie: PHP output within HTML page

am 09.08.2007 22:38:40 von dvader

> If he's stuck with pre-existing .html files and he can't rename them, I don't
> know of too many other options. : )

> If he were to change all his files to .php, to add dynamic content, the server
> would still have to parse all the content. It would probably take more time to
> rename all the files to the .php extension, then adjusting the config in
Apache.
> In either case the server would have to parse the PHP content whether it was
> working with .php or .html files.

True enough, but I was under the impression that he only wants/needs to do this
for a single page ("I am trying to add some dynamic content to an existing HTML
page."). I am just pointing out the cost of treating all passive files as PHP.

If he just wants to preserve an existing URL, he could use a simple redirect to
transfer the call to a PHP file.
--
Crash
Running: Windows 2000 Pro - Apache 2.2.4 - PHP 5.2.1 - PERL 5.8.8

Reply to group only. E-mail is blocked.

Re: Newbie: PHP output within HTML page

am 12.08.2007 17:26:55 von julienplee__hosted__

Le Wed, 08 Aug 2007 18:00:39 +0000, nospam a écrit :

> Hello,
>
> Sorry for the newbie question. I am trying to add some dynamic content
> to an existing HTML page. I would like to add a random saying to an
> area of a HTML doc. Sort of like a "fortune" - that would display a
> different fortune every minute.
>
> I figure that I can write a PHP script to select a random fortune from a
> file, but how do I embed that text within a HTML doc.I want to keep the
> HTML document just as it is now but add this php text. I don't want to
> rename MyHtml.html to MyHtml.php which I can do now.
>
> Is there a way to execute a external php script from within an HTML and
> have its return value displayed in the HTML?
>
> Thanks in advance,
> bruce

Hello Bruce,

You could embed it in a script tag referencing an external PHP file which
would generate ECMAScript for displaying your fortune sentences. The
counter part is that you will be able to display only few of them.
You're second choice could be to use AJAX based programming. This way,
you would be able to tell JavaScript to retrieve a sentence every X
minutes to display it.
Whatever you choose, you will have to use JavaScript if you don't want
your file to be parsed in PHP.


Julien