View Full Version : Resolved Band new to PHP
robin9000
02-02-2009, 05:04 PM
I have not ever used PHP before and I am tring to figure out how to use html inside a php document. Not only do I need to know how to include html coding inside a php document but I need to know how do I refure to the PHP document it in my html document once I have it created?
Thanks.
Snookerman
02-02-2009, 05:37 PM
Sound like you need some tutorials, here are a few good ones:
http://blog.themeforest.net/screencasts/diving-into-php-video-series/ (http://blog.themeforest.net/screencasts/diving-into-php-video-series/)
http://devzone.zend.com/article/627-PHP-101-PHP-For-the-Absolute-Beginner (http://devzone.zend.com/article/627-PHP-101-PHP-For-the-Absolute-Beginner)
Good luck!
robin9000
02-02-2009, 05:55 PM
Thanks for the links but the first dose not work and really all am looking for is just to know the begining tag and ending tag I need to use so that I can use html inside the PHP document.
Then I just need to know if it's the header or body where I link to the php document in my html file and what the tags are?
Schmoopy
02-02-2009, 06:27 PM
You can use PHP inside HTML, but you just have to save the file as .php, like so:
<?php
$title = "My page";
?>
<html>
<head>
<title><?php echo $title ?></title>
</head>
<body>
</body>
</html>
This would print out "My page" as the page's title.
To start the PHP tags you put <?php and to end them you type ?>
You can integrate these anywhere within your document.
Edit: Also, good tutorials there Snookerman, thanks.
robin9000
02-02-2009, 06:34 PM
No, no no. Mabye I did not say it right. I want to do the oposite of that. I want to use HTML inside a PHP file Then I want to incorporate the external PHP document into my HTML documents.
I was told it was possible, I just don't know how?
I know maybe it sounds wird but I have a good reason for wanting to do this.
Schmoopy
02-02-2009, 06:40 PM
Oh right sorry,
To be able to include php on HTML pages you still need to save that HTML file as .php to be able to include the file. It would be like this:
mypage.php
<html>
<head>
</head>
<body>
<?php include("header") ?>
</body>
</html>
header.php:
<?php
echo "I am a header, I can be included across multiple pages, all your base are belong to us";
?>
As far as I know you cannot include a PHP file into an HTML file, as HTML can't read PHP, so you need to save the initial HTML file as .php as well.
Snookerman
02-02-2009, 06:44 PM
You can use include or require for that. The tutorials I posted deal with that pretty well:
http://blog.themeforest.net/tutorials/diving-into-php-day-6/ (http://blog.themeforest.net/tutorials/diving-into-php-day-6/)
http://devzone.zend.com/node/view/id/636#Heading7 (http://devzone.zend.com/node/view/id/636#Heading7)
Good luck!
robin9000
02-02-2009, 06:49 PM
Maybe it's just me, so I will try to make it clear as to what I am trying to do.
I want to create a PHP file and include the following coding into the php file:
<div id="myslidemenu" class="jqueryslidemenu">
<ul>
<li><a href="http://www.dynamicdrive.com">Communications</a></li>
<!--Single row-->
<li><a href="#">Home</a>
<ul>
<li><a href="#">Location</a></li>
<li><a href="#">Disclaimer</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">F.A.Q.</a></li>
</ul>
</li>
<!--text-->
<li><a href="#">Services</a>
<ul>
<li><a href="#">WebDesign</a></li>
<li><a href="#">Computer</a>
<ul>
<li><a href="#">Sub Item 2.1.1</a></li>
<li><a href="#">Sub Item 2.1.2</a></li>
<li><a href="#">Folder 3.1.1</a>
<ul>
<li><a href="#">Sub Item 3.1.1.1</a></li>
<li><a href="#">Sub Item 3.1.1.2</a></li>
<li><a href="#">Sub Item 3.1.1.3</a></li>
<li><a href="#">Sub Item 3.1.1.4</a></li>
<li><a href="#">Sub Item 3.1.1.5</a></li>
</ul>
</li>
<li><a href="#">Sub Item 2.1.4</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="http://www.dynamicdrive.com/style/">Item 4</a></li>
</ul>
<br style="clear: left" />
</div>
Then I want to save that PHP file and I want to use it in my Html pages as the external PHP file witch it now is.
Please be pationte with me as I am knew to this and maybe I am not understanding everthing your telling me.
Thanks.
Schmoopy
02-02-2009, 07:33 PM
Yes, I understand what you mean, but the file you include the PHP file with must be php as well. You can't include a php file in a normal HTML file. Do the following:
1. Save the following code to a php file called menu.php
<?php
echo "<div id=\"myslidemenu\" class=\"jqueryslidemenu\">
<ul>
<li><a href=\"http://www.dynamicdrive.com\">Communications</a></li>
<!--Single row-->
<li><a href=\"#\">Home</a>
<ul>
<li><a href=\"#\">Location</a></li>
<li><a href=\"#\">Disclaimer</a></li>
<li><a href=\"#\">Contact Us</a></li>
<li><a href=\"#\">F.A.Q.</a></li>
</ul>
</li>
<!--text-->
<li><a href=\"#\">Services</a>
<ul>
<li><a href=\"#\">WebDesign</a></li>
<li><a href=\"#\">Computer</a>
<ul>
<li><a href=\"#\">Sub Item 2.1.1</a></li>
<li><a href=\"#\">Sub Item 2.1.2</a></li>
<li><a href=\"#\">Folder 3.1.1</a>
<ul>
<li><a href=\"#\">Sub Item 3.1.1.1</a></li>
<li><a href=\"#\">Sub Item 3.1.1.2</a></li>
<li><a href=\"#\">Sub Item 3.1.1.3</a></li>
<li><a href=\"#\">Sub Item 3.1.1.4</a></li>
<li><a href=\"#\">Sub Item 3.1.1.5</a></li>
</ul>
</li>
<li><a href=\"#\">Sub Item 2.1.4</a></li>
</ul>
</li>
</ul>
</li>
<li><a href=\"http://www.dynamicdrive.com/style/\">Item 4</a></li>
</ul>
<br style=\"clear: left\" />
</div>";
?>
2. Rename your current HTML file to have the extension .php instead of HTML. Example: index.html ---> index.php, you don't have to change anything else, just rename the file index.php
3. Put the include somewhere in index.php where you want the menu to be.
<html>
<head>
<title>My Page</title>
</head>
<body>
<div id="header">Welcome to my site</div>
<div id="menu"> // Include the menu in this div
<?php
include("menu.php");
?>
</div>
</body>
</html>
Just test that out, obviously the divs I made there aren't going to be the same on your page, but it was just to give you an idea.
You can then implement the same menu.php in different pages.
Hope that helps.
JasonDFR
02-02-2009, 09:19 PM
Just to clarify what Schmoopy said, you CAN include an .html file inside of a .php file.
But you CANNOT use include() or any other php functions inside of a file with any extension other than .php .
So:
<?php
include('menu.html'); // could be menu.txt, menu.inc, etc.
?>
is fine.
But,
<--! this is a file with a .html extenstion -->
include('file.php');
Won't work.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.