Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2008, 02:38 PM   PM User | #1
Jacobb123
Regular Coder

 
Join Date: Aug 2006
Posts: 311
Thanks: 0
Thanked 1 Time in 1 Post
Jacobb123 has a little shameless behaviour in the past
Regex question

I need to match the "Health" in the following line. I have more lines that I need to match they all follow the same pattern but of course the links change.

PHP Code:
<li><class="subtle" href="/dir/?link=list&sid=396545018">Health</a></li
Jacobb123 is offline   Reply With Quote
Old 01-11-2008, 02:50 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Jacobb123 View Post
I need to match the "Health" in the following line. I have more lines that I need to match they all follow the same pattern but of course the links change.

PHP Code:
<li><class="subtle" href="/dir/?link=list&sid=396545018">Health</a></li
Code:
/<a class="[^>]+>([^<]+)/
best regards
oesxyl is offline   Reply With Quote
Old 01-11-2008, 03:43 PM   PM User | #3
arnyinc
Regular Coder

 
Join Date: Jan 2003
Posts: 867
Thanks: 4
Thanked 8 Times in 8 Posts
arnyinc is an unknown quantity at this point
There is also a strip_tags function which would work:
PHP Code:
<?php
$text
='<li><a class="subtle" href="/dir/?link=list&sid=396545018">Health</a></li>';
$word=strip_tags($text);

echo 
$word;
?>
arnyinc is offline   Reply With Quote
Old 01-12-2008, 02:54 AM   PM User | #4
Jacobb123
Regular Coder

 
Join Date: Aug 2006
Posts: 311
Thanks: 0
Thanked 1 Time in 1 Post
Jacobb123 has a little shameless behaviour in the past
Thanks for the advice. I have another question related to this.

After using the regex and preg_match_all it matches the strings I need but also some that I don't want.

I am trying to scrape category listings from a site. All the categories are listed between <UL></UL> tags I only want to match the lines inside the <UL> tags. Is this possible?
Jacobb123 is offline   Reply With Quote
Old 01-12-2008, 07:02 AM   PM User | #5
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by Jacobb123 View Post
Thanks for the advice. I have another question related to this.

After using the regex and preg_match_all it matches the strings I need but also some that I don't want.

I am trying to scrape category listings from a site. All the categories are listed between <UL></UL> tags I only want to match the lines inside the <UL> tags. Is this possible?
Code:
/<ul>([^<]+)/m
all this can't help you if don't try to understand how regex work.

best regards

Last edited by oesxyl; 01-12-2008 at 11:32 AM..
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:09 PM.


Advertisement
Log in to turn off these ads.