Log in

View Full Version : new to php, please help



olsen
01-18-2009, 09:42 PM
I want to make an html file like this:

index.php

<?php include("header.inc.php"); ?>

<?php include("content.inc.php"); ?>

<?php include("footer.inc.php"); ?>

Then I want a command that will pick all this information up (same as what is shown with a rightclick showing source when running the inedx.php file) and save it to a new html file. How do I do that?

Thank you in advance.

Nile
01-18-2009, 09:54 PM
Can you be more descriptive on what you would like?
I don't understand your question.

olsen
01-18-2009, 10:15 PM
Thanks, I'll try.

I have three files, as shown, and I use the index.php to run them.
I then get an html file showing what was inside the three files, and it creates something like a homepage.
When you rightclick on a homepage you can read the sourcecode, collect it all and copy to a notepad and save it to a new html file.

Reason: All my headers and footers in about 100 hmtl files are identical, so I thought I could just work on the 'content' and somehow automate creating these 100 complete html files.

This is the first step in something that might turn out to get too complicated, but that is what I am trying to do.

Schmoopy
01-18-2009, 11:37 PM
Ah, yea this is a common way of not repeating yourself when creating pages. So all you have to do is have the code exactly as it was before but in the other files. So let's say header.php contains the following:



<html>

<head>
<title>My site name</title>
<link rel="stylesheet" type="text/css" href="styles/public.css/>
</head>

<body>



and then the footer.php contains:



<div id="footer"> Copyright &copy; </div>
</body>
</html>


Remember that you will have to rename your HMTL files to PHP files for the includes to work:



<?php include("header.php"); ?>
Content Here...

Bla bla <div> </div>

Etc...

At the end of the page now...

<?php include("footer.php"); ?>



And then you can always include another php content file mid way down if that is going to be repeated, hope you see how it works now,

Jack.

Edit: You could even add in a bit of dynamic content by setting your <title>My site name</title> to a variable (if it is a value that changes). So <title> <?php echo "$title"; ?> </title> and then set the title variable in the HTML file, like $title = "About";

olsen
01-18-2009, 11:57 PM
Thank you I'll give that a try and see how I do. Looks good.