How to link stylesheet in php file?

how can i link my all stylesheets in php file???

I’m sorry, I don’t really understand the question.
Could you elaborate?

Normally you can do something like this:

<?php
// PHP magic here
?>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>My title</title>
<link href="/styles.css" media="screen" rel="stylesheet" type="text/css" />
</head>

<body>

<?php
// More PHP magic here
?>

</body>
</html>

i want to to link stylesheets in a php file as i may use it in whole website

Sorry, this still doesn’t make sense.
What do you mean “link stylesheets”?

As Pullo has pointed out, style sheets go in the head section of your site. Do you have a head section? Is style sheet based on “theme” or something? If so you can make a little IF statement, otherwise add it to your head section.

<?php
// PHP magic here
?>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>My title</title>
<?php
	if($style == "style1"){
		echo '<link href="/style1.css" media="screen" rel="stylesheet" type="text/css" />';	
	}else{
		echo '<link href="/default.css" media="screen" rel="stylesheet" type="text/css" />';	
	}
?>
</head>

<body>

<?php
// More PHP magic here
?>

</body>
</html>

It sounds like the aim here is to use a PHP include that pulls in the style sheet onto each page. You can do it easily like so:

<?php include $_SERVER["DOCUMENT_ROOT"] . "/includes/styles.php"; ?>

In styles.php, you’d have something like this:

<link href="/styles/site.css" media="screen" rel="stylesheet" type="text/css" />

Normally I place a whole bunch of things into an include that gets pulled into the <head> section, like style sheet links, favicon etc.

Just following on from ralph.m, a little snippet of what you could use with the include statements.


@define("DOCUMENTROOT",$_SERVER["DOCUMENT_ROOT] . "/include/");
@define("SITEROOT","http://www.<EXAMPLE_WEBSITE>");
include(DOCUMENTROOT. "include/header.php");
// Main content generation
include(DOCUMENTROOT. "include/footer.php");

Header.php


<head>
<!-- Meta -->
<title></title>
<meta name="description" content=" " />
<meta name="keywords" content=" " />
<meta name="author" content=" " />
<!-- CSS -->
<link href="<?=SITEROOT;?>styles/site.css" media="screen" rel="stylesheet" type="text/css" />
</head>

Includes require server paths…

If your main HTML document is a template, you may wish to pull in different style sheets, depending on the content to be included further down the page. I do it by having the following in the <head>, after pulling in the basic style sheet with the usual link statement:


	<link rel="stylesheet" type="text/css" href="/css/basic.css" media="all" />
	<style type="text/css">
	<!--
<?php
	if (isset($css)) {
		echo "@import url(/css/" . $css . ");\
";
	}
	if (isset($css2)) {
		echo "@import url(/css/" . $css2 . ");\
";
	}
?>
	-->
	</style>

where $css, $css2 are file names such as ‘mystyle.css’.
This allows me to import further supplementary style sheets which can be different depending on the content that follows (which might be pages with information, or tables, or forms…).
Why have all these style sheets ? Well I find it easier to avoid conflicts that way than to keep thinking up new class names. And it keeps the style sheets short.