SSI - how to exclude parts of an "include" file?

Status
Not open for further replies.

deepwater

New Member
Messages
12
Reaction score
0
Points
0
having trouble finding help for this one...

i'd like to use SSI to include an HTML doc withing another HTML doc, but i want to automatically exclude parts of it, such as the 'head', 'body' and 'meta' tags, etc..
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Can you explain your situation a bit better? I cant quiet catch what you are trying to do.

Put a HTML document in an HTML document?
 

deepwater

New Member
Messages
12
Reaction score
0
Points
0
sure...

i happen to be working with index.html and i want to '<?php include("somefile.html"); ?>'. the problem is "somefile.html" has head, body and meta tags that i want to automatically exclude and i'm wondering how to do that, else index.html will now have 2 sets of head, body and meta tags.

the normal way, afik, would be to manually remove the tags in "somefile.html" and give it a different extension, like ".inc" or whatever, but i want visitors to be able to view both files by themselves, as well as combined in "index.html". the site is sort of a blog and i create a new "somefile.html" every day. the latest would get included in "index.html" while older ones get archived.
 
Last edited:

Pingy

New Member
Messages
46
Reaction score
0
Points
0
Heh, you threw me off for a second by mentioning SSI, but in the example above you used a PHP include, which definitely helped me realize your situation. What you are attempting to do is incredibly simple in PHP.

Instead of:
PHP:
<?php
include("somefile.html");
?>

Use:
PHP:
<?php
$strip = array('<html>', '</html>', '<head>', '</head>', '<body>', '</body>', '<title>', '</title>');
echo str_replace($strip, '', file_get_contents("somefile.html"));
?>

This should produce the results you're looking for. If you'd like to have any other tags stripped (other than the one's I've provided by default), simply add them to the array by imitating the example. Hope I've helped...
 
Last edited:

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
Instead of removing just the tags from the included files, I would create a third page that acts as a wrapper, which calls the included pages depending on what information the user wants displayed.

For example, use index.php to include content1.inc or content2.inc or both at the same time. Then use .htaccess mod_rewrite rules to redirect users to the correct content if they try to access the pages directly.

RewriteRule content1.html index.php?c=content1 [F]
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
hmm... always the same case senario.

I would have done something different.

PHP:
<?php
$tmp = getenv('QUERY_STRING');
if (!$$tmp) {
?>
<HTML>
. . .
</HEAD>
<?php
} else {
?>
<BODY>
. . .
</BODY>
<?php
}
?>

Not sure if you have the " } elsif (true/false value) {" function in php as this could be more effective.
 
Status
Not open for further replies.
Top