Hello fellow warriors, Category: I/O & Filtering
PHP Quicky - Fetching File Content and Stripping HTML/PHP
3
Hello fellow warriors,
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.
Perhaps you would like to keep Paragraph tags, or tables intacts. TO do this, the function takes on a third parameter (string) to allow certain tags.
From our example:
'Till next time,
WP4H
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.
Code:
$handle = @fopen("webpage.html", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgetss($handle, 4096);
echo $buffer;
}
fclose($handle);
} From our example:
Code:
change:
$buffer = fgetss($handle, 4096);
to
$buffer = fgetss($handle, 4096, "<table><tr><th><td>');
to keep tables intact WP4H
- twmaffun
- [1] reply
- shinepuppy
Next Topics on Trending Feed
-
3