Re: html parser
| From: | Justin French | Date: | Mon, 19 Aug 2002 05:19:45 +0000 |
| Subject: | Re: html parser | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-113175@lists.php.net to get a copy of this message | ||
Roman,
Please direct your question to the list, no to me personally. When I have
time on the list, I answer what I can... if I start answering questions off
list:
a) others don't benefit
b) others can't join in
c) I consider it a billable, personalised service to you
Parsing HTML is pretty complex stuff, and I haven't finished anything yet.
For me, I wanted to get all <A ...> tags, then get all the elements out of
it, change some, and glue it all back together, AND insert it back into the
HTML page in the right spot. Not easy! However it does help if you know
exactly what you want, and can limit the requirements.
HTML is a bitch to parse. There are tonnes options for attributes of a
link, like:
href=http://foo.com
href="http://foo.com"
href='http://foo.com'
href = "http://foo.com"
href = 'http://foo.com'
Then there's the different methods... http, ftp, mailto, javascript, etc
etc. Then there's the fact that you may only want to search for links
within your own domain, or only those outside your domain, and will you
want to keep query strings, port numbers, etc etc intact?
In your case, you might only want an array with a list of all the http://
URLs found in the page... eg:
$urls[1] => 'http://www.indent.com.au/home.php';
$urls[2] => 'http://www.indent.com.au/about.php';
$urls[3] => 'http://google.com';
OR, you might also want the
mailto:
ftp://
file:///
javascript:
...and whatever else in there as well.
OR you might want the whole hyperlink '<A' through to '>'.
It's not up to us to *guess* what you want to achieve. It's up to you to
CLEARLY SPECIFY the requirements.
1. what is your source?
a string?
a HTML file on disk?
a http:// URL on the web?
2. what specifically do you want to search for?
3. what do you want to do with the matches?
You need to be a LOT more specific.
Justin French
on 19/08/02 5:49 AM, Roman Belonohy´ (belonohy@centrum.cz) wrote:
> Hi man,
>
> I'd need to do a script which return all hyperlinks found on some webpage..
>
> You wrote about the similar script you're writing.
>
> Could you show me it or advice some approach ?
>
> thank you,
>
> Roman
>