Page 1 of 1
Remove HTML from current page being parsed
Posted: Fri Dec 31, 2004 6:53 am
by thomas777neo
Hi All
I load all my php pages through one central page i.e. container.php
It looks something like this:
Code: Select all
<?php
require("header.php");
require("page.php");
require("footer.php");
?>
The problem is this: I am trying to generate a PDF document. But because there is HTML in the header.php the PDF generation page show a whole bunch of garbage. Is there anyway to parse the page.php and remove the HTML at the same time. I understand that I can put if statements for the header and footer. Can it be done? Removing HTML on php execution, could be quite handy.
Posted: Fri Dec 31, 2004 8:50 am
by feyd
putting if's is the basic way.. seperating html from code is the better way.
Posted: Fri Dec 31, 2004 11:12 am
by rehfeld
you could also use output buffering, but its kinda like a band aid for this.
[php_man]ob_start()[/php_man]
[php_man]ob_end_clean()[/php_man]
Thanks
Posted: Mon Jan 03, 2005 2:20 am
by thomas777neo
Feyd, could you please show me a simple example. rehfeld, I tried the ob_ functions, it cleans up all the garbage but it doesn't remove the HTML.
Posted: Mon Jan 03, 2005 3:37 am
by feyd
here is a fairly simple example of template usage.
Posted: Mon Jan 03, 2005 11:32 am
by Shendemiar
I use this kind of thing for making a printable version of my page by removing most colors and making the page more document like by disabling all the links and forms etc.
I see no reason why it couldnt be used to remove html tags, but for that you'll need preg_raplace rather than str_replace.
Strip_Tags may also be of use.
Code: Select all
function links_off($a)
{
// remove links
$a = preg_replace("/<a(.*?)>/i", "<U>", $a);
$a = preg_replace("/<\/a>/i", "</U>", $a);
$a = preg_replace("/<A(.*?)>/i", "<U>", $a);
$a = preg_replace("/<\/A>/i", "</U>", $a);
// replace table css classes
$a = str_replace("Taulu0", "TauluprintB", $a);
// Then i remove lot's of other stuff with other commands like above
return $a;
}
ob_start("links_off");
// Here i generate my page
ob_end_flush();
feyd | use the