Re: Extract printable text from web page using preg_match
| From: | Martin Zvarík | Date: | Tue, 27 Feb 2007 18:22:00 +0000 |
| Subject: | Re: Extract printable text from web page using preg_match | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249509@lists.php.net to get a copy of this message | ||
I believe it is better to use strpos() in this case because it's faster.
<?php
$start = strpos(strtolower($website_code), '<body>');
// not necessary
$end = strpos(strtolower($website_code), '</body>');
$code = substr($website_code, $start, $end-$start);
echo strip_tags($code); // clean text
?>
This is very simple, but there are many HTML parsers out there if you want to do more complex stuff.
Martin
-----------------------
M5 napsal(a):
I am trying to write a regex function to extract the readable (visible, screen-rendered) portion of any web page. Specifically, I only want the text between the <body> tags, excluding any <script> or <style> tags within the document, also excluding comments. Has anyone here seen such a regex? Is it possible to do in one expression? ...Rene