How to use script tag of php in html file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

How to use script tag of php in html file

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<script src="your/php/file.php"></script>
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and what's in menu.php? It has to generate output the browser can parse as a client-side script.
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It won't work the way you think it will. HTML needs to be incorporated into the page itself.
User avatar
xinnex
Forum Commoner
Posts: 33
Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
xinnex
Forum Commoner
Posts: 33
Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark

Post 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..
Post Reply