Forum Moderators: coopster

Message Too Old, No Replies

Grabbing Data Between Two Constants

Using Regex Preg_match_all and php to grab data

         

teamcoltra

12:08 am on Jan 20, 2010 (gmt 0)

10+ Year Member



I have the following code:

<?php
//What I am getting
$_POST["stats"];

//my string
$string = $_POST["stats"];

//the regex
preg_match_all("/:\. Alliance Query Results ([\w\s%]+):\. Alliance Nation Statistics/", $string, $matches, PREG_PATTERN_ORDER);

//display it
foreach($matches[1] as $value)
{
echo "$value <br />";
}
?>


I want it to parse the data from:
<snip>

It seems as though that SHOULD Be correct, but its coming back blank.

For more detail here is what it should be looking for, and what it should return:

Looking For:


:. Alliance Query Results
Last Updated: 1/19/2010 5:30:03 PM

Alliance NameTotal NationsActive NationsPercent ActiveStrengthAvg. StrengthScore
North Atlantic Defense Coalition 142 84 59% 4,463,948 31,436 16.73
:. Alliance Nation Statistics

Should Return:


Alliance NameTotal NationsActive NationsPercent ActiveStrengthAvg. StrengthScore
North Atlantic Defense Coalition 142 84 59% 4,463,948 31,436 16.73

Furthermore (though this is outside of the scope of my question... as I really just want this data).. if someone has an idea on how to combine the two sets of data that goes together, that would be greatly appreciated:
For instance Alliance Name != Total Nations Alliance Name == North Atlantic Defense Coalition (which is right under it).

Since the spaces are also constant, I was thinking of possibly just counting out how many spaces it was until the result for each one... or something. Anyway this is just icing ... I would really just like to know how to get my current script working.

[edited by: eelixduppy at 1:42 am (utc) on Jan. 20, 2010]
[edit reason] no URLs, please [/edit]

teamcoltra

12:12 am on Jan 20, 2010 (gmt 0)

10+ Year Member



Sorry it should also include:
Last Updated: 1/19/2010 5:30:03 PM

In the results.