Re: extract/replace the content of html pages
| From: | Mike Migurski | Date: | Sat, 03 Jan 2004 00:43:23 +0000 |
| Subject: | Re: extract/replace the content of html pages | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-173659@lists.php.net to get a copy of this message | ||
>I have a folder full of html pages that I need to extract the content
>from. They all have <!-- content start --> and <!--content end -->
>comment tags surrounding the content. I need an easy way (not one at a
>time) to extract that content and place it in a new template.
>
>Any ideas are appreciated. Im assuming it will have to be some sort of
>strpos and substr thing, but I'm not sure how to automate my process
You want to get rid of the comments, or preserve the comments?
If the former, a simple preg_replace() will help. See the documentation
here: http://php.net/preg_replace,
http://php.net/pcre.pattern.syntax, and
http://php.net/pcre.pattern.modifiers. You will
search for pieces of text
bounded by '<!--' and '-->' that can span multiple lines. You will also
want to set the not-greedy modifier, so you don't clobber things like:
'<!-- comment -->not a comment<!-- comment -->'.
If the latter, you can use the third argument to preg_match_all() to save
above-matching comments strings into an array. See the documentation here:
http://php.net/preg-match-all.
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html