Current location: Hot Scripts Forums » Programming Languages » PHP » How retrieve all links in HTML page (regular expression)?


How retrieve all links in HTML page (regular expression)?

Reply
  #1 (permalink)  
Old 04-07-06, 05:28 AM
Jam2005 Jam2005 is offline
New Member
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy How retrieve all links in HTML page (regular expression)?

Hi Guys,

I have a very important problem

Let's say i have HTML page with the following content:

Code:
<html>
    <head>
        <title></title>
    </head>
    <body>
        Visit <a name="GoogleLink" href="http://www.google.com">Google
(top)</a><br /><br /><br />         Visit <a name="GoogleLinkBottom"
href="http://www.google.com">Google (bottom)</a>
   
</body>
</html>
I want to retrieve all links in this string. I use the following pattern matching to retrieve links:

$TMPPattern = "/(href|HREF)=[\"|\'](.*)[\n|\r|\"|\']/iU";
preg_match_all($TMPPattern, $String, $ArrayMatches, PREG_SET_ORDER)

This pattern only retrieves "href" and their values. I want more advanced pattern which will return both "href" and "name" parameters and their values. How can i do this? Help!!!

Thanks!
__________________
____________________________
Imagine the impossible
Impossible is nothing

Last edited by Jam2005; 04-07-06 at 05:29 AM. Reason: typo correction
Reply With Quote
  #2 (permalink)  
Old 04-07-06, 06:55 AM
gorivo's Avatar
gorivo gorivo is offline
Newbie Coder
 
Join Date: Mar 2006
Location: Lithuania
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
If I were you, I would use HTML SAX Parser class

You can download it from http://www.phpclasses.org/browse/package/2140.html
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 10:25 AM
To use include or embed HTML into my contact.php page dmaldon01 PHP 1 02-17-06 03:40 PM
Help with regular expression... :) eddyvlad PHP 2 01-08-06 10:10 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 07:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.