tags:

views:

41

answers:

4
<?php
// This is index.php
ob_start();
include 'tem/u.html';
ob_end_flush();
?>

<html>
<!-- This is u.html -->
<link rel="stylesheet" href="style.css" media="screen" /> 
<body>
<p> abc </p>
</body>
</html>

Now my problem is when i run h.html -> Ok with style.
But when i run index.php -> Ok without style (because now the index.php include style.css, not tem/style.css) Need a fix

+2  A: 

This has nothing to do with PHP or include. This has to do with your browser, and how URLs are interpreted.

When your browser is pointed at http://xyz.abc/tem/h.html and asked to load "style.css", it tries to load http://xyz.abc/tem/style.css - this is known as a relative url, relative to the current document location.

When your browser is at http://xyz.abc/index.php and is asked to load the stylesheet in the same way, it tries http://xyz.abc/style.css. Maybe you see the problem?

As for a solution, you might use a domain-relative path for the stylesheet ("/tem/style.css").

gnud
You mean href="/tem/style.css" right?. I know, but i see in WP template, they still use href="style.css" and everything works.
Snoob
@Snoob: If that works in WP, maybe they're using a `<base>` tag. Come to think of it, that's a better idea than the solution I gave in my answer.
David
Yes, they use bloginfo('stylesheet_url'). now i know what to do
Snoob
+2  A: 

If possible, refer to a domain relative path to the style.css, for example

<link rel="stylesheet" href="/style.css" media="screen" />

If that is not possible, you need to keep track on the page base in some way, which I cannot tell because I do not know enough about your application. But anyway, like

<link rel="stylesheet" href="<?php echo $pageBase; ?>/style.css" media="screen" />

where $pageBase is a variable containing the url to the root of your application.

Johan
How to have the url to the root of my application ( localhost/do -> this is root of my application). Are there any function know $baseurl?
Snoob
+2  A: 
David
A: 

just always use absolute path to your css file

<link rel="stylesheet" href="/tem/style.css" media="screen" />

that's all

Col. Shrapnel