Re: html stripping
| From: | Al | Date: | Fri, 05 Dec 2003 02:18:22 +0000 |
| Subject: | Re: html stripping | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171935@lists.php.net to get a copy of this message | ||
<php-general@mccullough-net.com> wrote in message
news:1070551538.3fcf51f221afd@webmail.mccullough-net.com...
> No this is not some shaddy game or strip poker knock-off. My question has
to
> do with a person project I have started. I have a script that grabs names
and
> ids from a database, puts them in an array and then based on that grabs a
URL
> and parses that URL for this name, drops all the html crap, and takes the
> information/stats and insert or updates the stats table. Problem is on
> certain names the page that it is parsing is different, and so I get loads
and
> loads of extra HTML, and one name in particular doesnt return all the
stats.
In essence what you're trying to do is spider / trawl web pages that do not
have consistent HTML formatting with inflexible functions like substr( ) and
str_replace( ) that are incapable of adapting to inconsistent search text.
You'd be much better off extracting the relevant data from HTML using
functions such as preg_match( ) and preg_replace( ) which let you search
over text using Perl-style regular expressions (aka regexes). Function
documentation can be found at:
http://au3.php.net/manual/en/function.preg-match.php
and
http://au3.php.net/manual/en/function.preg-replace.php
If you have no idea what a regex is, think of it as powerful, wildcard-based
searching. It allows you to write search expressions that are very tolerant
of changing search text and can still extract the data you need.
Regexes can be confusing when you start out. Try looking at this tutorial
for some starters: http://www.phpfreaks.com/tutorials/52/0.php
Good luck.
Al