本文整理汇总了PHP中domDocument类的典型用法代码示例。如果您正苦于以下问题:PHP domDocument类的具体用法?PHP domDocument怎么用?PHP domDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了domDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch_data_from_html
function fetch_data_from_html($remote_page)
{
// Returns an array of products and ratings
$product_rating_arr = array();
$html = get_html($remote_page);
$dom = new domDocument();
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
$table = $tables->item(0);
$rows = $table->getElementsByTagName('tr');
$i = 0;
foreach ($rows as $row) {
if ($i != 0) {
$columns = $row->getElementsByTagName('td');
$product = $columns->item(0)->textContent;
$rating = $columns->item(1)->textContent;
$image = $columns->item(2)->textContent;
$var = $product . "__" . $image;
$product_rating_arr[$var] = $rating;
}
$i += 1;
}
return $product_rating_arr;
}
示例2: checkLogin
public function checkLogin(){
$document = new domDocument();
$document->load("users/users.xml");
$xpath = new domXpath($document);
$nodelist = $xpath->query("/*/user[string(login) = '$this->login']");
return ($nodelist->length == 0)?false:true;
}
示例3: readContent
function readContent()
{
$data = read_xml_file($this->server, $this->port, $this->url);
if (strlen($data) > 0) {
$dom = new domDocument();
$dom->loadXML(substr($data, 0, strrpos($data, '>') + 1));
$arrFeeds = array();
$count = 0;
foreach ($dom->getElementsByTagName('item') as $node) {
if (function_exists('date_parse')) {
$date_raw = date_parse($node->getElementsByTagName('pubDate')->item(0)->nodeValue);
//$date = date('H:i j.m.Y', mktime($date_raw['hour'], $date_raw['minute'], $date_raw['second'], $date_raw['month'], $date_raw['day'], $date_raw['year']));
$date = date('j.m', mktime($date_raw['hour'], $date_raw['minute'], $date_raw['second'], $date_raw['month'], $date_raw['day'], $date_raw['year']));
} else {
$date1 = explode(' ', $node->getElementsByTagName('pubDate')->item(0)->nodeValue);
$months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$months_n = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
$time = explode(':', $date1[4]);
//$date = $time[0] . ':' . $time[1] . ' ' . intval($date1[1]) . '.' . str_replace($months, $months_n, $date1[2]) . '.' . $date1[3];
$date = intval($date1[1]) . '.' . str_replace($months, $months_n, $date1[2]);
}
$itemRSS = array('title' => mb_convert_case(!$this->decodeUTF ? utf8_decode($node->getElementsByTagName('title')->item(0)->nodeValue) : $node->getElementsByTagName('title')->item(0)->nodeValue, MB_CASE_UPPER, "UTF-8"), 'description' => substr(!$this->decodeUTF ? utf8_decode($node->getElementsByTagName('description')->item(0)->nodeValue) : $node->getElementsByTagName('description')->item(0)->nodeValue, 0, 60), 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue);
$itemRSS['date'] = $date;
array_push($arrFeeds, $itemRSS);
$count++;
if ($count == $this->nr_of_posts) {
break;
}
}
return $arrFeeds;
}
return null;
}
示例4: findWspolrzedne
public function findWspolrzedne($adres, $miasto)
{
$adresTrim = trim($adres);
$adresReplaceSpace = str_replace(' ', '+', $adresTrim);
$LettersToChange = array('ó', 'ż', 'ź', 'ś', 'ę', 'ą', 'ł', 'ń', 'ć');
$LettersChanged = array('o', 'z', 'z', 's', 'e', 'a', 'l', 'n', 'c');
$adresWithoutPolishLetters = str_replace($LettersToChange, $LettersChanged, $adresReplaceSpace);
$curl1 = curl_init();
curl_setopt($curl1, CURLOPT_URL, "http://www.zumi.pl/namapie.html?qt=&loc={$miasto}%2C+{$adresWithoutPolishLetters}&Submit=Szukaj&cId=&sId=");
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
$stronaZumi = curl_exec($curl1);
curl_close($curl1);
$dom = new domDocument();
@$dom->loadHTML($stronaZumi);
$dom->preserveWhiteSpace = false;
$szukana = array();
$divs = $dom->getElementsByTagName('div');
foreach ($divs as $div) {
$script = $div->getElementsByTagName('script');
$szukana[] = $script->item(0)->nodeValue;
}
foreach ($szukana as $text) {
if (strpos($text, 'objDefLoc')) {
$a = substr($text, -29);
$letterToRemove = array(':', '"', 'y', 'x', '}');
$wspolrzedne1 = str_replace($letterToRemove, '', $a);
$poz = strpos($wspolrzedne1, ',');
$dlugosc = substr($wspolrzedne1, $poz);
$dlugosc = str_replace(',', '', $dlugosc);
$szerokosc = substr($wspolrzedne1, 0, $poz);
$wspolrzedne[] = "{$dlugosc},{$szerokosc}";
}
}
return $wspolrzedne[0];
}
示例5: viewInfo
function viewInfo($node)
{
if ($_POST["model1"] == "telefon") {
$nameEl = "телефона";
}
if ($_POST["model2"] == "noutbuk") {
$nameEl = "ноутбука";
}
if ($_POST["model3"] == "printer") {
$nameEl = "принтера";
}
echo "<tr>\n\t\t<td><b>Марка " . $nameEl . "</b>\n\t\t</td><td><b>Год выпуска</b>\n\t</td></tr>";
$document = new domDocument("1.0", "utf-8");
$document->load("test3.xml");
$nodelist = $document->getElementsByTagName("model");
$model = $nodelist->item($i);
for ($i = 0; $i < $nodelist->length; $i++) {
$model = $nodelist->item($i);
if ($model->parentNode->nodeName == $node || $model->parentNode->nodeName == "asort:" . $node) {
$name = $model->childNodes->item(0);
$year = $model->childNodes->item(1);
echo "<tr>\n\t\t\t\t<td>" . $name->nodeValue . "</td>\n\t\t\t\t<td align='center'>" . $year->nodeValue . "</td>\n\t\t\t</tr>";
}
}
}
示例6: getContent
public function getContent($params = array())
{
$awsCachePath = CACHEPATH . "/aws.status.cxml";
$data = array();
$neededLocations = array();
$services = array('Amazon Elastic Compute Cloud', 'Amazon Relational Database Service', 'Amazon Simple Storage Service');
$compliance = array('us-east-1' => array('name' => 'NA_block', 'filter' => array('N. Virginia', 'US Standard')), 'us-west-1' => array('name' => 'NA_block', 'filter' => 'N. California'), 'us-west-2' => array('name' => 'NA_block', 'filter' => 'Oregon'), 'sa-east-1' => array('name' => 'SA_block', 'filter' => ''), 'eu-west-1' => array('name' => 'EU_block', 'filter' => ''), 'ap-southeast-1' => array('name' => 'AP_block', 'filter' => 'Singapore'), 'ap-southeast-2' => array('name' => 'AP_block', 'filter' => 'Sydney'), 'ap-northeast-1' => array('name' => 'AP_block', 'filter' => 'Tokyo'));
if (empty($params['locations'])) {
$neededLocations = $this->getUsedLocations();
$params['locations'] = $neededLocations;
} else {
$neededLocations = $params['locations'];
}
if (file_exists($awsCachePath) && time() - filemtime($awsCachePath) < 3600) {
clearstatcache();
$time = filemtime($awsCachePath);
$data = (array) json_decode(file_get_contents($awsCachePath));
} else {
$html = @file_get_contents('http://status.aws.amazon.com');
if ($html) {
$dom = new domDocument();
$dom->validateOnParse = false;
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
foreach ($compliance as $compKey => $compValue) {
$div = $dom->getElementById($compValue['name']);
$tables = $div->getElementsByTagName('table');
$rows = $tables->item(0)->getElementsByTagName('tr');
foreach ($rows as $row) {
$cols = $row->getElementsByTagName('td');
if (preg_match('/(.*)(' . implode('|', $services) . ')(.*)/', $cols->item(1)->nodeValue)) {
$regionFilter = $compValue['filter'];
if (is_array($compValue['filter'])) {
$regionFilter = implode('|', $compValue['filter']);
}
if (preg_match('/(.*)(' . $regionFilter . ')(.*)/', $cols->item(1)->nodeValue)) {
$img = '';
$message = '';
if ($cols->item(0)->getElementsByTagName('img')->item(0)->getAttribute('src') == 'images/status0.gif') {
$img = 'normal.png';
} else {
$img = 'disruption.png';
$message = $cols->item(2)->nodeValue;
}
$data[$compKey][substr(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), 0, strpos(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), ' ('))] = array('img' => $img, 'status' => $cols->item(2)->nodeValue, 'message' => $message);
$data[$compKey]['locations'] = $compKey;
}
}
}
}
file_put_contents($awsCachePath, json_encode($data));
}
}
$retval = array('locations' => json_encode($neededLocations));
foreach ($neededLocations as $value) {
$retval['data'][] = $data[$value];
}
return $retval;
}
示例7: __construct
/**
* Brief Description.
* Complete Description.
*
* @param $file' (tipo) desc
*
* @returns (tipo) desc
*
*/
public function __construct($file = '', $options = 0)
{
$this->tree = null;
$this->stack = array();
// this keeps track of what tag level you're at
$doc = new domDocument();
$doc->preserveWhiteSpace = false;
$doc->load($file, $options);
$root = $doc->documentElement;
$this->parse($doc);
}
示例8: bench2
function bench2()
{
global $XML;
$dom = new domDocument();
$dom->loadxml($XML);
$children = $dom->getElementsByTagName('title');
foreach ($children as $v) {
$arr[] = $v->nodeValue;
}
return $arr;
}
示例9: main
function main()
{
$dom = new domDocument();
$string = <<<END
<a>
<b>c</b>
</a>
END;
$dom->loadXML($string);
$s = simplexml_import_dom($dom);
$dom = null;
var_dump((string) $s->b);
}
示例10: get_pre
function get_pre($url)
{
$html = file_get_contents($url);
// a new dom object
$dom = new domDocument('1.0', 'utf-8');
// load the html into the object ***/
@$dom->loadHTML($html);
//discard white space
$dom->preserveWhiteSpace = false;
$pre = $dom->getElementsByTagName('pre');
//Get elements by desired tag.
return htmlspecialchars($pre->item(0)->nodeValue);
}
示例11: getCompteDisplay
function getCompteDisplay()
{
$dom = new domDocument();
$arr = array(utf8_decode('é') => "\\351", utf8_decode('è') => "\\350", utf8_decode('ç') => "\\347", utf8_decode('à') => "\\340", utf8_decode('ù') => "\\371");
$clientdata = strtr($_SESSION['client'], $arr);
$dom->loadXML($clientdata);
if (!$dom) {
echo "Error while parsing the document\n";
exit;
}
$s = simplexml_import_dom($dom);
return strtoupper($s->nom) . ' ' . strtoupper($s->prenom) . ',' . $s->clientid . ',' . $s->type;
}
示例12: __construct
public function __construct($html, $baseurl)
{
$doc = new domDocument();
$doc->loadHTML($html);
$this->body = $doc->getElementsByTagName('html')->item(0)->getElementsByTagName('body')->item(0);
$this->lines = array();
$this->line = (object) array('text' => '', 'wrap' => true, 'prefix' => "\n");
$this->pre = 0;
$this->indent = array();
$this->baseurl = $baseurl;
$this->links = array();
$this->linkcount = 0;
}
示例13: prepareContent
function prepareContent($content)
{
if (!$content) {
return '';
}
$dom = new domDocument();
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$image->setAttribute('src', site_url($src));
}
return $dom->saveHTML();
}
示例14: get_instituicao_cursos
function get_instituicao_cursos($cod_endereco, $cod_instituicao)
{
$html = file_get_contents('http://emec.mec.gov.br/emec/consulta-ies/listar-curso-endereco/d96957f455f6405d14c6542552b0f6eb/' . base64_encode($cod_instituicao) . '/aa547dc9e0377b562e2354d29f06085f/' . base64_encode($cod_endereco) . '/list/1000');
include_once './src/simple_html_dom.php';
$dom = new domDocument();
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('tbody');
foreach ($tables as $row) {
$cols = $row->getElementsByTagName('td');
$array[] = preg_replace("/[^A-Za-z]/", "", $cols->item(0)->nodeValue);
}
return $array;
}
示例15: getSelectedItems
/**
* Extract selected items array from html multiselect tag
*
* @param array Html multiselect tag
* @return array Selected items array
*/
private function getSelectedItems($html)
{
$dom = new domDocument();
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$options = $dom->getElementsByTagname('option');
$items = array();
foreach ($options as $option) {
if ($option->hasAttribute('selected')) {
$items[] = $option->nodeValue;
}
}
return $items;
}