I am really new to php and am attempting to create a news reader on my site.

I have gotten it running just fine in a page of its own, BUT, I need it to be inside a php include. How do I link different scripts and stylesheets in the "body" as opposed to the head?

I feel like this is really simple, but I am just not sure of the syntax.

How do I take this code from the head and make it work in the body?

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link href="ncahd-main.css" rel="stylesheet" type="text/css" /> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> 
<script src="../js/jquery.zrssfeed.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function () {
	$('#test').rssfeed('..news.xml', {
		limit: 3
<div id="test"></div> 

Recommended Answers

All 4 Replies

There is no standard way to include anything inside a PHP file. However, if the site is hosted by the Apache webserver and mod_include is loaded then in your PHP script you can use:

<!--#include virtual="/folder/file.ext"-->
Member Avatar for diafol

Sorry, don't understand. HEAD scripts and css files are placed in the head because they are supposed to be in the head - not the body.

However, you can certainly include anything in an include file and include it anywhere in a html file.

What you can't do is run or include a php file from javascript, unless you're implementing Ajax.

For a general example to include a php file:


You could have raw javascript in this file and you can get it to run when the page reaches the client (browser) - that is after all the php has done its work. What you can't do is the opposite (run php code from js).

Hope that answers the question. Come back if not. If you're creating a generic RSS reader that reads loads of different xml files based on a list link for example - you just need javascript (jquery is great for this) - no need for php.

Was a bit to quick with my reply. Like ardav says, there is an include in php. Server side includes is what my reply is all about and is used for including files in html.

Put this into a PHP file:

echo '<script type="text/javascript"> 
         $(document).ready(function () {
	 $("#test").rssfeed("..news.xml", {
		limit: 3

Then in your <body> use:

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

Don't quote me on the concatenation, you may have to play around with the syntax (change some of the ' and ").

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.