Forum Moderators: coopster

Message Too Old, No Replies

regex check optional URL in the data with list items

it fails to fetch data if it has <ul> and a url within it

         

phparion

7:09 am on Aug 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

My target HTML output has values between a th and td pair of tags for which I am using this pattern which works very good

preg_match_all("/<th class=\"bel\">[\/\(\)-:<>\w\s]+<\/th>[\/\(\)-:<>\w\s]+<td class=\"value\">[\/\(\)-:<>\w\s\$\.]*<\/td>/",$cnt,$mat2);

and fetch out all information. but sometimes for one <td></td> pair an optional URL also comes and in that case my regex fails to fetch that URL value... the html looks like

<th class="bel">label</th>
<td class="value"><ul>
<li>

<a
href="http://www.example.com/string/string.html"
title="title here"
>
URL name</a>

</li>
</ul>
</td>

this <ul><li> </li></ul> code is optional, it appears in some pages and have a simple string in some pages

for the string value my regex works but if it has the URL within list items then my regext doesn't read it. I have tried many patterns including the following

preg_match_all("/<th class=\"bel\">[\/\(\)-:<>\w\s]+<\/th>[\/\(\)-:<>\w\s]+<td class=\"value\">[\/\(\)-:<>\w\s\$\.](<ul><li>)?[\/\(\)-:<>\w\s\$\.]*(<\/li><\/ul>)?<\/td>/",$cnt,$mat2);

can anybody help me please how to read this optional URL?

thank you

[edited by: eelixduppy at 2:27 pm (utc) on Sep. 4, 2007]
[edit reason] disabled smiles [/edit]

eelixduppy

2:48 pm on Sep 13, 2007 (gmt 0)



Have any luck with this yet?