A couple of patterns

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Frexuz
Forum Newbie
Posts: 5
Joined: Mon Oct 22, 2007 8:55 am

A couple of patterns

Post by Frexuz »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


HTML code that I want to fetch values from:
[syntax="html"]    <tr height="25">
        <td>
          <table cellspacing="0" cellpadding="0" align="center">
            <tr>
                <td align="center">
                  <a href="javascript:openWindow('view_scores.php?user=22553&song=216')">
                    <span style="font-size: 0.7em">View All</span>
                  </a>
                </td>
            </tr>
          </table>
        </td>
        <td align="center">3</td>
        <td align="center">Shout at the Devil</td>
        <td align="center"><a href="rankings.php?game=2&diff=4&song=216&page=86&highlight=4262" class="rank3">4262nd</a></td>
        <td align="center">157,330</td>
        <td align="center"><img src="/images/rating_6.gif" /> (6.2)</td>
        <td align="center"><span class="percent2">95%</span></td>
        <td align="center">137</td>
        <td align="center">Aug. 9, 2007, 3:49PM</td>
        <td align="center"><span class="gray">N/A</span>
    </tr>
I want to be able to fetch these values:
Shout at the Devil (name that can vary. Can include numbers, apostrophes etc.)
(6.2) (only the numbers vary, there is always two numbers with a dot in between)
157,330 (can be xx,xxx or xxx,xxx, and there is always a comma)
95% (can be xx% or xxx%)
137 (1-4 digits)

The easiest way should be the get everything between every <tr> and </tr>
Then take out the 3rd, 5th, 6th, 7th, and 8th: <td align="center">*value*</td>

I hope you guys understand Every possible solution is good. [s]Thx[/s] thanks.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

What have you tried so far?
There are 10 types of people in this world, those who understand binary and those who don't
Schatten
Forum Newbie
Posts: 3
Joined: Mon Sep 24, 2007 10:23 am

Post by Schatten »

Why don't you use DOMDocument ?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Guess we need more detail before we provide meaningful answers. Questions I would like to ask include...
Are you fixed with that HTML ?
- Have you looked at XML at all ?
- Have you tried adding meaningful id's or names to the html tags with what you need to capture.

Is this needed on the client side (javascript to pull information and submit it) or server side (php processes a complete HTML file) ?
Post Reply