Page 1 of 1
How to use script tag of php in html file
Posted: Wed Jan 24, 2007 10:39 pm
by jdhorton77
I'm trying to come up with an index file that is html and I want to be able to use the php command of include. I know html has a tag called <script> that you can use for javascript along with php, but I'm not sure on how the syntax would go. Can someone give me a clue. Thanks.
Posted: Wed Jan 24, 2007 10:49 pm
by volka
Code: Select all
<script src="your/php/file.php"></script>
Posted: Wed Jan 24, 2007 11:30 pm
by jdhorton77
Ok, I tried what you said and it's not working for some reason. I have my path correct. Here is my code if it helps.
Code: Select all
<td>
<script src="http://Somewhere.com/menu.php"></script>
</td>
And thanks for the help.
Posted: Wed Jan 24, 2007 11:36 pm
by volka
and what's in menu.php? It has to generate output the browser can parse as a client-side script.
Posted: Wed Jan 24, 2007 11:56 pm
by jdhorton77
yeah it's mainly html code. I'm using it as a templete I guess you could say, I'm going to include it in all pages to reduce redundancy. It's a table with <dl> tags and other list tags.
Posted: Thu Jan 25, 2007 12:07 am
by feyd
It won't work the way you think it will. HTML needs to be incorporated into the page itself.
Posted: Thu Jan 25, 2007 3:45 pm
by xinnex
try the following..
The client-side of things (index.html):
Code: Select all
<html>
<head>
</head>
<body>
<script type="text/javascript" src="content.php">
</script>
</body>
</html>
The server-side of things (content.php):
Code: Select all
<php
$content = '<h1>hello world!</h1>';
?>
document.write('<?php echo $content?>');
This is a VERY simplified example to get you started with. You should probably look into dom-manipulation via Javascript or better yet the "buzzed up" AJAX-techniques.
Posted: Thu Jan 25, 2007 3:49 pm
by feyd
There's no reason to do this with Javascript, let alone Ajax. Just put the HTML in with the rest of the HTML.
Posted: Thu Jan 25, 2007 5:08 pm
by xinnex
Agreed, but he asked for a way to include output from php in a static html-file =)
...Right?
edit: didn't make sense first time around..