Current location: Hot Scripts Forums » Programming Languages » PHP » Need help with this regular expression


Need help with this regular expression

Reply
  #1 (permalink)  
Old 11-10-09, 10:14 AM
kevinkhandublin kevinkhandublin is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Need help with this regular expression

i want to extract link and link title from this html format..

PHP Code:

<div class="sresult_address">

                            <
h2>
                                
2.
                                                                        
<a href="http://www.mydomain.eu/property-for-sale/Cape-View-House-Restored-Georgian-House-With-Stunning-Sea-Views-London/485539/">
                                            
Cape View HouseRestored Georgian House With Stunning Sea Views,London                                         </a>
                                                                </
h2>
                        </
div
im looking for a regular expression that will be able to extract these..

This is the one i came up with but doesn't seem to work

PHP Code:

'~<div class="sresult_address"><h2>\s*[0-9]{1,2}[.]\s*<a href="([^"]*)">(.*?)</a></h2></div>~is'
Is there something wrong with this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-10-09, 04:29 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
You might want to try strpos, then trim.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-11-09, 09:23 AM
carters-site's Avatar
carters-site carters-site is offline
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
I have seen multiple posts about parsing HTML from your username. If you are scraping sites you might want to be careful about putting other people's content on your own site (assuming you do not have permission).

If you have permission there should be a better way of getting this data for instance a RSS feed or if they have an API you can tie into to get the data cleanly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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
Help with Regular Expression coolsaggu PHP 3 09-29-08 07:25 AM
PHP regular expression problem coolsaggu PHP 0 08-08-08 03:58 AM
Regular Expression mohit Everything Java 9 05-08-08 05:55 AM
Help with regular expression... :) eddyvlad PHP 2 01-08-06 11:10 PM
regular expression for parsing url link musmanm80 Perl 1 07-28-05 12:58 AM


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