PHP not working with HTML

General discussions related to php

Moderators: macek, egami, gesf

HashTag0
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Sep 26, 2012 1:02 pm

PHP not working with HTML

Postby HashTag0 » Wed Sep 26, 2012 1:21 pm

Hello all,

I'm new here & in PHP scripting.

My PHP is not properly working within html files.

Code: Select all

<html>
<head>
        <title>Hello</title>
</head>
<body>
<?php
echo "<h2>Hello World</h2>";
?>
</body>
</html>

When I browse the above file (save as hello1.html) in web_browsers it shows: Hello World"; ?>
But the same PHP section (<?php.....?>) works if I write it in a .php without any html tags. The tutorials I've seen all use
php & html. :(

My operating is CentOS 5 & PHP is php-5.1.6-39.el5_8

How to solve this thing?

Thanks.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP not working with HTML

Postby egami » Wed Sep 26, 2012 2:26 pm

Code: Select all


<?php
echo phpinfo();
?>

HashTag0
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Sep 26, 2012 1:02 pm

Re: PHP not working with HTML

Postby HashTag0 » Thu Sep 27, 2012 6:44 am

egami wrote:

Code: Select all


<?php
echo phpinfo
();
?>


IT shows a large page with Php information. I've attached a screenshot of it.
Attachments
phpinfo.png
phpinfo.png (96.69 KiB) Viewed 404 times

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP not working with HTML

Postby egami » Thu Sep 27, 2012 7:25 am

I completely skipped over the obvious.

.php will execute in .php extension files, not .html.

rename the file to hello.php and try it again.

HashTag0
New php-forum User
New php-forum User
Posts: 3
Joined: Wed Sep 26, 2012 1:02 pm

Re: PHP not working with HTML

Postby HashTag0 » Thu Sep 27, 2012 6:41 pm

Now it's working with .php extension.
Thank you :)

ictvacature
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Sep 30, 2012 8:53 pm

Re: PHP not working with HTML

Postby ictvacature » Sun Sep 30, 2012 8:57 pm

this is such a nice and useful information for us...i appreciate urs word ...Thank you

Informatiemanager
PHP programmeur


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest