2 回答
TA贡献1786条经验 获得超13个赞
尝试一下:
preg_match_all('/\<option value\="([a-z0-9]+)">([A-Za-z0-9\_\-]+)\<\/option\>/', $str, $match, PREG_SET_ORDER);
$profiles = array();
foreach($match as $row) {
$profiles[$row[2]] = $row['1'];
}
print_r($profiles);
TA贡献1859条经验 获得超6个赞
我需要以下功能:
// convert html response into SimpleXML
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML($response);
$xmlSite = simplexml_import_dom($dom);
// initialize processing values
$devices = [];
$options = [];
$filters = [];
// parse SimpleXML with xpath to get current data
$rows = $xmlSite->xpath('//tr/td[@title=@datalabel]'); // these are the rows with assignments of devices to filters
foreach ($rows as $row) {
$key = utf8_decode((string)$row->attributes()['title']); // name (label) of the devices
if (preg_match('/Alle /', $key)) { // skip standard settings
continue;
}
$select = $row->xpath('parent::*//select[@name]'); // find the line with the currently assigned ID for the device
$value = (string)$select[0]->attributes()['name']; // get the current ID ('profile:user*' or 'profile:landevice*')
$devices[$key] = $value;
$options = $select[0]->xpath('option'); // the defined filters (dropdown in each row)
foreach ($options as $option) {
$profiles[utf8_decode((string)$option)] = (string)$option->attributes()['value']; // get label and ID of filters
if (isset($option->attributes()['selected'])) { // determine the filter currently assigned to the device
$filters[$value] = (string)$option->attributes()['value']; // get device (ID) and filter (ID)
}
}
}
- 2 回答
- 0 关注
- 444 浏览
添加回答
举报