Presuming that the structure is very reliably like that, try the following:
$htmlCode = "...";
$matches = array();
if (preg_match_all('/name="(initval|endval)"\s+value="([^"]+)"/', $htmlCode, $matches)) {
$formValues = array_combine($matches[1], $matches[2]);
} else {
// error
}
This assumes only whitespace between the name
and value
attributes, you'll need to make a small change if it differs. preg_match_all() returns an array with the whole regexp match at [0]
, and then the individual group matches in their corresponding locations [1]
& [2]
, the array combine takes one as keys, one as values and puts it together so you have an associative lookup to get your results.