本文整理汇总了PHP中domDocument::getElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:PHP domDocument::getElementsByTagName方法的具体用法?PHP domDocument::getElementsByTagName怎么用?PHP domDocument::getElementsByTagName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domDocument
的用法示例。
在下文中一共展示了domDocument::getElementsByTagName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read_manifest
public static function read_manifest()
{
global $base_path;
$informations = array();
@ini_set("zend.ze1_compatibility_mode", "0");
$manifest = new domDocument();
$module_path = realpath(dirname($base_path . "/cms/modules/" . str_replace("cms_module_", "", get_called_class()) . "/" . get_called_class() . ".class.php"));
$manifest->load($module_path . "/manifest.xml");
//on récupère le nom
$name = $manifest->getElementsByTagName("name")->item(0);
$informations['informations']['name'] = cms_module_root::charset_normalize($name->nodeValue, "utf-8");
//on récupère le(les) auteur(s)
$informations['informations']['author'] = array();
$authors = $manifest->getElementsByTagName("author");
for ($i = 0; $i < $authors->length; $i++) {
$author = array();
//on récupère son nom
$author['name'] = cms_module_root::charset_normalize($authors->item($i)->getElementsByTagName('name')->item(0)->nodeValue, "utf-8");
//on récupère son organisation
$organisation = $authors->item($i)->getElementsByTagName("organisation");
if ($organisation->length > 0) {
$author['organisation'] = cms_module_root::charset_normalize($organisation->item(0)->nodeValue, "utf-8");
}
$informations['informations']['author'][] = $author;
}
//on récupère les dates
$created_date = $manifest->getElementsByTagName("created_date")->item(0);
$informations['informations']['created_date'] = cms_module_root::charset_normalize($created_date->nodeValue, "utf-8");
$updated_date = $manifest->getElementsByTagName("updated_date");
if ($updated_date->length > 0) {
$informations['informations']['updated_date'] = cms_module_root::charset_normalize($updated_date->item(0)->nodeValue, "utf-8");
}
//on récupère la version
$version = $manifest->getElementsByTagName("version")->item(0);
$informations['informations']['version'] = cms_module_root::charset_normalize($version->nodeValue, "utf-8");
// on récupère la langue par défaut du module...
$informations['informations']['default_language'] = self::get_module_default_language($manifest);
// administrable?
$informations['informations']['managed'] = $manifest->getElementsByTagName("managed") && $manifest->getElementsByTagName("managed")->item(0)->nodeValue == "true" ? true : false;
//fournisseur de liens?
$informations['informations']['extension_form'] = $manifest->getElementsByTagName("extension_form") && $manifest->getElementsByTagName("extension_form")->item(0)->nodeValue == "true" ? true : false;
@ini_set("zend.ze1_compatibility_mode", "0");
//on récupère la listes des éléments utilisés par le module...
$use = $manifest->getElementsbyTagName("use")->item(0);
$informations['elements_used'] = self::read_elements_used($use);
@ini_set("zend.ze1_compatibility_mode", "1");
return $informations;
}
示例2: 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];
}
示例3: 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;
}
示例4: 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>";
}
}
}
示例5: 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;
}
示例6: addUser
public function addUser(){
$document = new domDocument();
$document->load("users/users.xml");
$root = $document->getElementsByTagName("users")->item(0);
$user = $root->appendChild(new domElement("user"));
$user->appendChild($document->createElement("login", "$this->login"));
$user->appendChild($document->createElement("password","$this->pass"));
$document->save("users/users.xml");
}
示例7: findMonitor
public function findMonitor($szukana)
{
$curl1 = curl_init();
curl_setopt($curl1, CURLOPT_URL, "http://www.samsung.com/pl/function/espsearch/searchResult.do?keywords={$szukana}&input_keyword={$szukana}");
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
$strona1 = curl_exec($curl1);
curl_close($curl1);
$dom1 = new domDocument();
@$dom1->loadHTML($strona1);
$dom1->preserveWhiteSpace = false;
$nazwa = array();
$a = $dom1->getElementsByTagName('a');
foreach ($a as $a) {
$class = $a->getAttribute('class');
$href = $a->getAttribute('href');
$nazwa[$class] = $href;
}
$nazwa2 = $nazwa['arrow_blue'];
$url = "{$nazwa2}&tab=specification";
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, "{$url}");
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
$strona2 = curl_exec($curl2);
curl_close($curl2);
$tabela = array();
$dom2 = new domDocument();
@$dom2->loadHTML($strona2);
$dom2->preserveWhiteSpace = false;
$nazwa = $dom2->getElementsByTagName('h1');
$tabela['nazwa'] = $nazwa->item(0)->nodeValue;
$rows = $dom2->getElementsByTagName('tr');
foreach ($rows as $row) {
$th = $row->getElementsByTagName('th');
$nazwa = $th->item(0)->nodeValue;
$nazwa2 = $th->item(1)->nodeValue;
$td = $row->getElementsByTagName('td');
$wartosc = $td->item(0)->nodeValue;
$tabela[trim($nazwa)] = trim($wartosc);
$tabela[trim($nazwa2)] = trim($wartosc);
}
$correctTable = $this->removeAllWrongValueFromTable($tabela);
return $correctTable;
}
示例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: __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;
}
示例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: 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();
}
示例12: domDocument
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;
}
示例13: parseTags
private function parseTags($tag = '', $source = "")
{
if (!$tag) {
throw new Exception\CrawlException('Tag has type of null');
}
/*** a new dom object ***/
$dom = new \domDocument();
@$dom->loadHTML($source);
/*** remove silly white space ***/
$dom->preserveWhiteSpace = false;
/*** get the links from the HTML ***/
// $tag->setTag('a');
$tags = $dom->getElementsByTagName($tag);
return $tags;
}
示例14: readhtml
function readhtml()
{
$dom = new domDocument();
$dom->loadHTMLFile("docs/KUNNAMKUL.html");
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
/*** get all rows from the table ***/
$rows = $tables->item(0)->getElementsByTagName('tr');
/*** loop over the table rows ***/
$dataArray = array();
foreach ($rows as $row) {
/*** get each column by tag name ***/
$cols = $row->getElementsByTagName('td');
/*** echo the values ***/
if ($cols->item(0)->nodeValue) {
$tmpArray = array();
$tmpArray[] = $cols->item(0)->nodeValue;
$name = $cols->item(1)->getElementsByTagName('p');
$tmpArray[] = $name->item(0)->nodeValue;
$tmpstring = isset($name->item(1)->nodeValue) ? $name->item(1)->nodeValue : '';
$tmpstring .= isset($name->item(2)->nodeValue) ? $name->item(2)->nodeValue : '';
$tmpstring .= isset($name->item(3)->nodeValue) ? $name->item(3)->nodeValue : '';
$tmpArray[] .= $tmpstring;
//$tmpArray[]=$cols->item(1)->nodeValue;
$bsdob = $cols->item(2)->getElementsByTagName('p');
$tmpArray[] = $bsdob->item(0)->nodeValue;
$tmpArray[] = isset($bsdob->item(1)->nodeValue) ? $bsdob->item(1)->nodeValue : '';
$tmpArray[] = isset($bsdob->item(2)->nodeValue) ? $bsdob->item(2)->nodeValue : '';
//$tmpArray[]=$bsdob->item(2)->nodeValue;
$factorinfo = $cols->item(3)->getElementsByTagName('p');
$tmpArray[] = isset($factorinfo->item(0)->nodeValue) ? $factorinfo->item(0)->nodeValue : '';
$tmpArray[] = isset($factorinfo->item(1)->nodeValue) ? $factorinfo->item(1)->nodeValue : '';
$dpan = $cols->item(4)->getElementsByTagName('p');
$tmpArray[] = $dpan->item(0)->nodeValue;
$tmpArray[] = isset($dpan->item(1)->nodeValue) ? $dpan->item(1)->nodeValue : '';
$tmpArray[] = isset($dpan->item(2)->nodeValue) ? $dpan->item(2)->nodeValue : '';
$dataArray[] = $tmpArray;
}
}
$this->load->library('table');
$tmpl = array('table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">');
$this->table->set_template($tmpl);
echo $this->table->generate($dataArray);
}
示例15: _grab
private function _grab($date)
{
$content = new domDocument();
// кривая разметка камы
@$content->loadHTML(file_get_contents($this->_url . '?date=' . date('Y-m-d', $date)));
$rows = $content->getElementsByTagName('tr');
$result = array();
for ($i = 2; $i < $rows->length; $i++) {
$cols = $rows->item($i)->getElementsByTagName('td');
$item = array('title' => $cols->item(1)->nodeValue, 'description' => 'Зал: ' . $cols->item(4)->nodeValue, 'fire_at' => date('Y-m-d ', $date) . trim(substr($cols->item(0)->nodeValue, 2)));
if ($cols->item(4)->nodeValue == 1) {
$item['description'] .= sprintf("\n\nЭконом: %s р.\nVIP: %s р.", $cols->item(2)->nodeValue, $cols->item(3)->nodeValue);
} else {
$item['description'] .= sprintf("\n\nЦена: %s р.", $cols->item(3)->nodeValue);
}
$result[] = $item;
}
return $result;
}