php - Inconsistent records with simple_html_dom -
i trying utilize simple_html_dom , php pick records page in form: name/job/address. problem not every record stores value 'job'. page has 10 records, , 2 of them record person's job, if utilize following:
foreach($html->find('span[class="name"]') $e) { $name[]=$e->innertext; } foreach($html->find('span[class="job"]') $e) { $job[]=$e->innertext; } foreach($html->find('span[class="address"]') $e) { $address[]=$e->innertext; } then when come access 3 arrays find $job array 2 records long, while names , addresses 10 long, , don't know of 10 names 2 jobs 'belong' to. there way of keeping arrays 'in step' each other, or other way of keeping records coherently intact here?
thank you.
then insert null value when job node empty!!
foreach($html->find('span[class="job"]') $e) { $value=$e->innertext; if (empty($value)) $job[] = null; else $job[] = $value; } or using shorthand if-else version $job[] = (empty($value) ? null : $value);
php simple-html-dom dynamic-arrays
No comments:
Post a Comment