PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Jul 21, 2019 2:32 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Mar 01, 2012 3:57 pm 
Offline
Forum Newbie

Joined: Thu Mar 01, 2012 3:39 pm
Posts: 6
I need to parse out some web pages, hopefully they are all formatted correctly but since I'm new to Regexp I'm unsure how to grab info from after a key occurrence.

Ex.
<th scope="row" style="text-align:left;"><a href="/City_of_license" title="City of license">City of license</a></th>
<td class="" style=""><a href="/Airdrie,_Alberta" title="Airdrie, Alberta">Airdrie, Alberta</a></td>

I need to place Airdrie, Alberta under a heading of City of license, getting all the info into a text file is all I need, I can then populate a DB from there.

How is this done? I have other info on the page as well but Once I figure out how to do this I can apply it to the others.
I was thinking of find the first instance of "City of license" then the first title=" and grab the text until " is reached.

Thanks


Top
 Profile  
 
PostPosted: Thu Mar 01, 2012 9:58 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Dec 15, 2011 2:40 pm
Posts: 85
Location: Nelson, NZ
Hi Ron,

I don't think I fully understand what we're trying to achieve.
Can you please provide the desired output? That will make it easier to work on the regex.

Wishing you a fun weekend.


Top
 Profile  
 
PostPosted: Fri Mar 02, 2012 11:17 am 
Offline
Forum Newbie

Joined: Thu Mar 01, 2012 3:39 pm
Posts: 6
I posted a reply last night but now it's not here...Hmm

Here is an excerpt from one of the web pages:

<th scope="row" style="text-align:left;"><a href="/City_of_license" title="City of license">City of license</a></th>
<td class="" style=""><a href="/Airdrie,_Alberta" title="Airdrie, Alberta">Airdrie, Alberta</a></td>
</tr>
<tr class="">
<th scope="row" style="text-align:left;">Branding</th>
<td class="" style="">Air 106-1</td>
</tr>
<tr class="note">

<th scope="row" style="text-align:left;"><a href="/Slogan" title="Slogan">Slogan</a></th>
<td class="" style="">Airdrie's Radio Station</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left;"><a href="/Frequency" title="Frequency">Frequency</a></th>
<td class="" style="">106.1 <a href="/MHz" title="MHz" class="mw-redirect">MHz</a></td>
<th scope="row" style="text-align:left;"><a href="/Radio_format" title="Radio format">Format</a></th>
<td class="category" style=""><a href="/Adult_top_40" title="Adult top 40" class="mw-redirect">Adult top 40</a></td>

on my first pass I want to write to a file
City of license Airdrie, Alberta
then
Frequency 106.1
then
Radio format Adult top 40
...
I cannot just look for the title=" before the data because there is more than one title=", I would like to search for the first occurrence of title=" after a string, i.e. City of license

Clear as mud?

Thanks

Ron


Top
 Profile  
 
PostPosted: Fri Mar 02, 2012 3:33 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Dec 15, 2011 2:40 pm
Posts: 85
Location: Nelson, NZ


Top
 Profile  
 
PostPosted: Thu Mar 08, 2012 2:20 pm 
Offline
Forum Newbie

Joined: Thu Mar 01, 2012 3:39 pm
Posts: 6
Thanks works great!


Top
 Profile  
 
PostPosted: Thu Mar 08, 2012 2:35 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Dec 15, 2011 2:40 pm
Posts: 85
Location: Nelson, NZ
Glad to hear it, Ron, thanks for letting me know. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group