parse html node content

在使用之前先导入类文件:

require_once 'simple_html_dom.php';

 使用:

		foreach ($results as $row) {
			$html = new simple_html_dom();
			$html->load($row['html']);
			$ret = $html->find('td.productOptionPrompt');			
			$id = $row['id'];
			if (count($ret)) {
				foreach ($ret as $e) {
					$option_id = $e->first_child()->value;
					$option_name = trim($e->innertext);
					$pos = strpos($option_name,'<');
					$option_name = trim(substr($option_name,0,$pos));
					$option_value_name_ret = $html->find('#productOptionValues'.$option_id . ' div label.productOptionValueName');
					$option_value_name = array();
					foreach ($option_value_name_ret as $ovne) {
						$option_value_name[] = trim($ovne->innertext);
					}
					
					$option_value_id_ret = $html->find('#productOptionValues'.$option_id . ' div input');
					$option_value_id = array();
					foreach ($option_value_id_ret as $key=>$ovir) {
						$option_value_id[] = (int)trim($ovir->value);
						//检查是不是存在
						if (!$this->existsProductOption($row['mid'],$option_id,(int)trim($ovir->value))) {
							$sql ="insert into old_product_option_value(`option_id`,`option_value_id`,`option_name`,`option_value_name`,`product_id`)
									values(?,?,?,?,?)";
							$write->query($sql,array($option_id,(int)trim($ovir->value),$option_name,$option_value_name[$key],$row['mid']));
							
							
						}
					}
					$options = array(
							'product_id'=>$row['mid'],
							'option_id' => $option_id,
							'option_name' => $option_name,
							'option_value_id'=>$option_value_id,
							'option_value_name'=>$option_value_name
					);
					var_dump($options);
				}
			}
		}

 

你可能感兴趣的:(content)