I want this code to check if a element exists and then get the number of records inside the div.
html
<div id=myDiv>This table contains 5 records (3 seconds)</div>
php
$selector = new Zend_Dom_Query($response->getBody());
$nodes = $selector->query('#myDiv');
if (count($nodes) < 1) {
$this->setValue(0);
return;
}
$el = $nodes->current();
if (preg_match('#(\d+[\d,]*)\s+result#i', $el->nodeValue, $matches)) {
$number = str_replace(',', '', $matches[1]);
$this->setValue(intval($number));
} else {
Zend_Registry::get('log')->err(get_class($this).': Unable to match response and regex.');
$this->setValue(0);
}
Right now it gets to the bottom $this->setValue(0), so it can find the element. There must be something wrong with the regex, and that’s where Im clueless.
if (preg_match('#(\d+[\d,]*)\s+result#i', $el->nodeValue, $matches)) {
The HTML code does not contain anything that would match
#(\d+[\d,]*)\s+result#i, the expression requires the string “result” to be present.You probably want to change that word to “record”. E.g: