/** * Extract a single value * * @param \QueryPath\DOMQuery $item * @param array $mapping * @param string $value * @return string */ protected function _extractValue(\QueryPath\DOMQuery $item, array $mapping, $value = '') { if ($item) { if (!empty($mapping['attr'])) { $value = $item->attr($mapping['attr']); } elseif (!empty($mapping['innerHTML'])) { $value = $item->innerHTML(); } else { $value = $item->text(); } } $value = mb_convert_encoding($value, 'UTF-8', 'auto'); if (!empty($mapping['preg'])) { if (preg_match($mapping['preg'], $value, $matches)) { $value = isset($matches[1]) ? $matches[1] : $matches[0]; } } if (!empty($mapping['wrap'])) { $value = str_replace('|', $value, $mapping['wrap']); } if (!empty($mapping['strtotime'])) { $value = strtotime($value); } if (!isset($mapping['trim']) || !empty($mapping['trim'])) { $value = trim($value); } return $value; }