Input content into a DIV within an HTML file from a PHP file
I'm not sure if this is even possible but if it is I imagine it would be via PHP (which I am a total beginner at).
Basically I have an .html file with an empty DIV tag in it and I am hoping to get the content of that DIV tag, which is stored in a .php file, and put it into the DIV.
To try and make this a bit clearer...
HTML FILE
<div id="content">
</div>
and...
CSS
#content {
position:relative;
width:700px;
max-height:550px;
min-height:10px;
overflow:auto;
}
#content h1 {
font-family:"Kristen ITC";
font-size:20px;
font-weight:bold;
margin-top:20px;
margin-bottom:0px;
margin-left:70px;
text-align:left;
color:#000000;
text-decoration:underline;
}
#content p {
font-family:"Bradley Hand ITC";
font-size:22px;
font-weight:bold;
margin-top:0px;
margin-bottom:0px;
margin-left:90px;
margin-right:130px;
text-align:left;
color:#000000;
text-decoration:none;
}
And then, I am hoping to have this...
<h1>- Chapter 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus molestie orci at orci blandit consectetur dapibus elit sollicitudin. Donec diam libero, feugiat vitae egestas eget, pellentesque eget tellus.</p>
<h1>- Chapter 2</h1>
<p>Phasellus in libero at ligula tincidunt convallis et a libero. Ut elementum molestie enim, vitae consequat mi imperdiet in. Ut metus justo, pharetra vel convallis et, eleifend vitae est. Aenean fringilla tincidunt nunc ac gravida.</p>
In a .php file, which I will then link to within the .html file, like this...
HTML FILE
<div id="content">
(Somehow link the .php. file here t开发者_StackOverflowo get the <h1> and <p> stuff)
</div>
I hope this makes sense.
I have currently tried (remember I'm a beginner so don't laugh if I'm just being stupid)...
HTML FILE
<div id="content">
$contents = file_get_contents('current.php');
</div>
with the php file being...
PHP FILE
<?php
// print output
<h1>- Chapter 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus molestie orci at orci blandit consectetur dapibus elit sollicitudin. Donec diam libero, feugiat vitae egestas eget, pellentesque eget tellus.</p>
<h1>- Chapter 2</h1>
<p>Phasellus in libero at ligula tincidunt convallis et a libero. Ut elementum molestie enim, vitae consequat mi imperdiet in. Ut metus justo, pharetra vel convallis et, eleifend vitae est. Aenean fringilla tincidunt nunc ac gravida.</p>
?>
I have no idea what I'm doing, whether I'm relatively close to making this work, completely miles away from achieving it or if it's even possible.
In a perfect world where I could just use the .html file and .css file, it would look like this example I made on jsfiddle
Can anyone help me with this?
You're including a file (not 1:1 copy'ing the contents of the file). Try:
<div id="content">
<?php include('current.php'); ?>
</div>
This will strip <?php ... ?>
tags, hope it helps. Documentation is available.
Use this:
HTML FILE
<div id="content">
<?php
echo file_get_contents('current.php');
?>
</div>
Get rid of the <?php
and ?>
in your "php" file, which just contains plain HTML.
If you want to add dynamic content, at the server's side, you have to contain PHP code within <?php
and ?>
. When you're defining plain HTML, do NOT use <?php
, because <?php
tells the interpreter to parse the contents between <?php
and ?>
as PHP code.
you should use the file_get_contents('sourcefile.php') function which allows retrieve the source file content.
If the source file includes code , you may use require() or include(). For further information read php.net manual.
精彩评论