PHP Quicky - Fetching File Content and Stripping HTML/PHP
Category: I/O & Filtering
Difficulty: Beginner
This quicky is useful for those of us who need to quickly strip out all HTML and PHP from a file. Say you have a webpage that you would like to only see the content without the tags, well.. this tip is for you:
the fgetss() function read from a file and outputs the content with tags, both HTML and PHP removed.
$handle = @fopen("webpage.html", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgetss($handle, 4096);
echo $buffer;
}
fclose($handle);
} From our example:
change:
$buffer = fgetss($handle, 4096);
to
$buffer = fgetss($handle, 4096, "<table><tr><th><td>');
to keep tables intact WP4H
Get your FREE Lifetime Affiliate Tracking System here