本文整理汇总了PHP中DomDocument::getElementsByTagName方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::getElementsByTagName方法的具体用法?PHP DomDocument::getElementsByTagName怎么用?PHP DomDocument::getElementsByTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomDocument
的用法示例。
在下文中一共展示了DomDocument::getElementsByTagName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recuperePodcast
public function recuperePodcast($url_flux, $nom_abonnement)
{
if (!empty($url_flux) && !empty($nom_abonnement)) {
//On recupere le nom de l'abonnement
$nom_abo = $nom_abonnement;
//On recupère le flux RSS
$flux = new DomDocument();
$flux->load($url_flux);
$flux->preservedWhiteSpace = false;
$i = 0;
$pc = $flux->getElementsByTagName('item')->item($i);
while (!is_null($pc)) {
$titre = mysql_real_escape_string($pc->getElementsByTagName('title')->item(0)->nodeValue);
$date = mysql_real_escape_string($pc->getElementsByTagName('pubDate')->item(0)->nodeValue);
$desc = mysql_real_escape_string($pc->getElementsByTagName('description')->item(0)->nodeValue);
$auteur = mysql_real_escape_string($pc->getElementsByTagName('author')->item(0)->nodeValue);
$categ = mysql_real_escape_string($pc->getElementsByTagName('category')->item(0)->nodeValue);
$url = mysql_real_escape_string($pc->getElementsByTagName('enclosure')->item(0)->getAttribute('url'));
//Ajout base
$sql = "INSERT INTO podcast(titre,auteur,date,description,url,id_genre,comments) VALUES('{$titre}','{$auteur}', '{$date}', '{$desc}', '{$url}', '{$categ}',' rien ')";
@mysql_query($sql) or die('Erreur requete SQL' . " " . mysql_error());
$id_podcast = mysql_insert_id();
$sql2 = "INSERT INTO abonnement(id_util,id_pod,url,nom_abo) VALUES('1','{$id_podcast}', '{$url_flux}', '{$nom_abo}')";
@mysql_query($sql2) or die('Erreur requete SQL' . " " . mysql_error());
$i = $i + 1;
$pc = $flux->getElementsByTagName('item')->item($i);
}
}
}
示例2: exec
/**
*
* @param string $html
*/
public function exec($html)
{
mb_language('Japanese');
// 1.プリプロセス
// scriptテキスト削除
// script内に文字列リテラルの閉じタグがあるとDomDocumentがscriptのソースを#text扱いしてしまうので
// script内の文字を削除する
// 正規表現で削除しようとするとSegmentation faultが発生する(StackOverFlow?)ので
// simple_html_domでscript内文字列を削除
// MAX_FILE_SIZEの制限にひっかかったので、ソースを編集してデフォルトの3倍に変更している
$simpleHtml = str_get_html($html);
foreach ($simpleHtml->find('script') as $script) {
$script->innertext = '';
}
$html = $simpleHtml->outertext;
// トリム
// $html = preg_replace('/(\s| )+/mi', ' ', $html);
// 2. dom生成
$doc = new DomDocument("1.0", "utf-8");
@$doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$node = $doc->getElementsByTagName('body')->item(0);
$this->preProcessedInput = $node->textContent;
// 3.プロパティを初期化
$this->domXPath = new DomXPath($doc);
$this->title = @$doc->getElementsByTagName('title')->item(0)->textContent;
$text = $this->scan($node);
$this->textAll = $text;
$this->domCountAll = $this->domCount;
$this->pancutuationCountAll = $this->calcKutenScore($text) + $this->calcTotenScore($text);
$this->textLengthAll = mb_strlen($text);
$this->highScore = -1000000;
$this->extracedNode = null;
// 4.実行
$this->extract($node);
}
示例3: buildModel
public function buildModel($model)
{
try {
$dom = new DomDocument();
$dom->Load($this->loadModel($model));
$rooms_base = $dom->getElementsByTagName("roomdata");
foreach ($rooms_base as $rooms_bases) {
$roomtypes = $rooms_bases->getElementsByTagName("roomtype")->item(0)->nodeValue;
$caption = $rooms_bases->getElementsByTagName("caption")->item(0)->nodeValue;
$model_name = $rooms_bases->getElementsByTagName("model_name")->item(0)->nodeValue;
$description = $rooms_bases->getElementsByTagName("description")->item(0)->nodeValue;
if ($this->createRooms($roomtypes, $caption, $username, $description, $model_name)) {
echo 'Done rooms<br/>';
}
}
foreach ($dom->getElementsByTagName("roomitem") as $room_items) {
foreach ($room_items->getElementsByTagName("item") as $item) {
$base_item = $item->getElementsByTagName("base_item")->item(0)->nodeValue;
$x = $item->getElementsByTagName("x")->item(0)->nodeValue;
$y = $item->getElementsByTagName("y")->item(0)->nodeValue;
$z = $item->getElementsByTagName("z")->item(0)->nodeValue;
$rot = $item->getElementsByTagName("rot")->item(0)->nodeValue;
$coord = array('x' => $x, 'y' => $y, 'z' => $z);
if ($this->addItemsToRooms($user_id, null, $base_item, $coord, $rot)) {
echo 'Done ' . $base_item . '<br/>';
}
}
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例4: breakTopicMetadaOnCharacter
/**
* Break the MODS topic element text-node metadata on
* the specified character and put into seperate MODS topic elements.
*
* @param string $xmlsnippet The initial MODS topic element.
*
* @param string $breakOnCharacter The charcter break the string.
* The default character is the semicolon ';'.
*
* @return string
* An XML string containing one or more MODS topic elements.
*/
public function breakTopicMetadaOnCharacter($xmlsnippet, $breakOnCharacter = ';')
{
// Break topic metadata on ; into seperate topic elements.
$xml = new \DomDocument();
$xml->loadxml($xmlsnippet, LIBXML_NSCLEAN);
$topicNode = $xml->getElementsByTagName('topic')->item(0);
if (!is_object($topicNode)) {
$xmlstring = $xmlsnippet;
} else {
$topictext = $topicNode->nodeValue;
$topics = explode($breakOnCharacter, $topictext);
// remove old topic node.
$topicNodeParent = $topicNode->parentNode;
$topicNode->parentNode->removeChild($topicNode);
$subjectNode = $xml->getElementsByTagName($this->topLevelNodeName)->item(0);
foreach ($topics as $topic) {
$topic = trim($topic);
$newtopicElement = $xml->createElement('topic');
$topictextNode = $xml->createTextNode($topic);
$newtopicElement->appendChild($topictextNode);
$subjectNode->appendChild($newtopicElement);
unset($topictextNode);
unset($newtopicElement);
}
$xmlstring = $xml->saveXML($subjectNode);
}
return $xmlstring;
}
示例5: storeSitemap
/**
*
* @param DomDocument $index
* @param DomDocument $sitemap
*/
protected function storeSitemap($index, $sitemap)
{
// Записываем текущий файл
$name = sprintf('sitemap_list_%d.xml', $index->getElementsByTagName('sitemap')->length);
$result = $sitemap->saveXML();
file_put_contents(FILE_PATH . $name, $result);
//
//
$sitemapEl = $index->createElement('sitemap');
$loc = $index->createElement('loc', 'http:' . \Extasy\CMS::getWWWRoot() . 'files/' . $name);
$lastMod = $index->createElement('lastmod', date('Y-m-d'));
$sitemapEl->appendChild($loc);
$sitemapEl->appendChild($lastMod);
$index->getElementsByTagName('sitemapindex')->item('0')->appendChild($sitemapEl);
}
示例6: getPreview
public function getPreview($elements)
{
if (!isset($this->preview)) {
if (!isset($elements)) {
$elements = 2;
}
// Get just the text (no markup) from a node using $node->textContent.
// Compare the textContent value to the one returned by $node->nodeValue.
libxml_use_internal_errors(true);
$dom = new DomDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $this->Body . '</body></html>');
$dom->normalize();
$nodes = $dom->getElementsByTagName("body")->item(0)->childNodes;
$elementCount = 0;
$this->preview = '';
foreach ($nodes as $node) {
if ($node->nodeType === XML_ELEMENT_NODE) {
$this->preview .= $dom->saveXML($node);
$elementCount++;
if ($elementCount === $elements) {
break;
}
}
}
// Carriage returns in the XML prevent the markup from validating. -- cwells
$this->preview = str_replace(' ', '', $this->preview);
}
return $this->preview;
}
示例7: testUpdateOnLicenceChange
public function testUpdateOnLicenceChange()
{
$document = $this->createTestDocument();
$document->store();
$documentCacheTable = new Opus_Db_DocumentXmlCache();
$docXmlCache = $documentCacheTable->find($document->getId(), '1')->current()->xml_data;
$domDoc = new DomDocument();
$domDoc->loadXML($docXmlCache);
$licences = $domDoc->getElementsByTagName('Licence');
$this->assertTrue($licences->length == 0, 'Expected no Licence element in dom.');
$licence = new Opus_Licence();
$licence->setNameLong('TestLicence');
$licence->setLinkLicence('http://example.org/licence');
$licenceId = $licence->store();
$document->setServerState('published');
$document->setLicence($licence);
$docId = $document->store();
$licence = new Opus_Licence($licenceId);
$licence->setNameLong('TestLicenceAltered');
$licence->store();
$docXmlCacheResult = $documentCacheTable->find($document->getId(), '1');
$this->assertTrue($docXmlCacheResult->count() == 0, 'Expected empty document xml cache');
$this->executeScript('cron-update-document-cache.php');
$docXmlCacheAfter = $documentCacheTable->find($docId, '1')->current()->xml_data;
$domDocAfter = new DomDocument();
$domDocAfter->loadXML($docXmlCacheAfter);
$licencesAfter = $domDocAfter->getElementsByTagName('Licence');
$this->assertTrue($licencesAfter->length == 1, 'Expected one Licence element in dom.');
$licences = $document->getLicence();
$licences[0]->delete();
}
示例8: capi_mkfeedtitle
function capi_mkfeedtitle($feed)
{
global $_SGLOBAL, $_SN, $_SCONFIG;
$feed['title_data'] = empty($feed['title_data']) ? array() : unserialize($feed['title_data']);
if (!is_array($feed['title_data'])) {
$feed['title_data'] = array();
}
//title
$searchs = $replaces = array();
if ($feed['title_data'] && is_array($feed['title_data'])) {
foreach (array_keys($feed['title_data']) as $key) {
if ($key === "touser") {
$dom = new DomDocument();
@$dom->loadHTML($feed["title_data"]["touser"]);
$urls = $dom->getElementsByTagName('a');
$url = $urls->item(0);
$value["title_data"]["touser"] = capi_fhtml($value["title_data"]["touser"]);
}
$searchs[] = '{' . $key . '}';
$replaces[] = $feed['title_data'][$key];
}
}
$searchs[] = '{actor}';
$replaces[] = empty($actors) ? $_SN[$feed['uid']] : implode(lang('dot'), $actors);
$feed['title_template'] = mktarget(str_replace($searchs, $replaces, $feed['title_template']));
return $feed;
}
示例9: get_xml_droits
function get_xml_droits()
{
if (!is_file(PATH_ROOT . 'inc/droits.xml')) {
return array();
}
$dom = new DomDocument("1.0", "UTF-8");
$dom->load(PATH_ROOT . 'inc/droits.xml');
$elements = $dom->getElementsByTagName('droits');
$arbre = $elements->item(0);
$array_droit = array();
$sections = $arbre->childNodes;
foreach ($sections as $section) {
if ($section->nodeName == "section") {
$nom_section = $section->attributes->getNamedItem("name")->nodeValue;
$array_droit[$nom_section] = array();
$droits = $section->childNodes;
foreach ($droits as $droit) {
if ($droit->nodeName == "droit") {
$infos_droit = $droit->childNodes;
$nom_droit = $droit->getElementsByTagName("name")->item(0)->nodeValue;
$type_droit = $droit->getElementsByTagName("type")->item(0)->nodeValue;
$array_droit[$nom_section][$nom_droit] = array($type_droit);
}
}
}
}
return $array_droit;
}
示例10: call_success
public function call_success()
{
global $USER, $COURSE, $CFG;
if (empty($this->_xmlresponse)) {
if (is_siteadmin($USER->id)) {
notice(get_string('adminemptyxml', 'adobeconnect'), $CFG->wwwroot . '/admin/settings.php?section=modsettingadobeconnect');
} else {
notice(get_string('emptyxml', 'adobeconnect'), '', $COURSE);
}
}
$dom = new DomDocument();
$dom->loadXML($this->_xmlresponse);
$domnodelist = $dom->getElementsByTagName('status');
if ($domnodelist->item(0)->hasAttributes()) {
$domnode = $domnodelist->item(0)->attributes->getNamedItem('code');
if (!is_null($domnode)) {
if (0 == strcmp('ok', $domnode->nodeValue)) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
示例11: manipulate
/**
* General manipulate wrapper method.
*
* @param string $input An XML snippet to be manipulated. We are only interested
* in <abstract> snippets.
*
* @return string
* Manipulated string
*/
public function manipulate($input)
{
$dom = new \DomDocument();
$dom->loadxml($input, LIBXML_NSCLEAN);
$abstracts = $dom->getElementsByTagName('abstract');
if ($abstracts->length == 1) {
$abstract = $abstracts->item(0);
// Use Guzzle to hit the API.
$client = new Client();
try {
$original_text = urlencode($abstract->nodeValue);
$query = "?text={$original_text}&format=json";
$response = $client->get($this->arrpiUrl . $query);
// If there is a Guzzle error, log it and return the original snippet.
} catch (Exception $e) {
$this->log->addWarning("PiratizeAbstract", array('HTTP request error' => $e->getMessage()));
return $input;
}
$body = $response->getBody();
$translation = json_decode($body, true);
$abstract->nodeValue = urldecode($translation['translation']['pirate']);
// Log any instances where the translation differs from the original text.
if (urldecode($original_text) != $abstract->nodeValue) {
$this->log->addInfo("PiratizeAbstract", array('Record key' => $this->record_key, 'Source abstract text' => urldecode($original_text), 'Piratized abstract text' => $abstract->nodeValue));
}
// We're done, so return the modified snippet.
return $dom->saveXML($dom->documentElement);
} else {
return $input;
}
}
示例12: __toString
/**
* return the document as string.
*
* @access public
* @return string
*/
public function __toString()
{
$this->document->formatOutput = true;
$this->document->preserveWhitespace = false;
$title = $this->document->createElement('title', $this->getFullTitle());
$this->head->appendChild($title);
if (!empty($this->favicon)) {
$favicon = $this->document->createElement('link');
$favicon->setAttribute('rel', 'shortcut icon');
$favicon->setAttribute('href', $this->favicon);
$this->head->appendChild($favicon);
$favicon = $this->document->createElement('link');
$favicon->setAttribute('rel', 'icon');
$favicon->setAttribute('href', $this->favicon);
$this->head->appendChild($favicon);
}
if (!empty($this->keywords)) {
$keywords = $this->document->createElement('meta');
$keywords->setAttribute('name', 'keywords');
$keywords->setAttribute('content', $this->keywords);
$this->head->appendChild($keywords);
}
$html = $this->document->getElementsByTagName('html')->item(0);
$html->appendChild($this->head);
$html->appendChild($this->body);
return $this->document->saveXML();
}
示例13: array
function get_input_tags($html)
{
$post_data = array();
// a new dom object
$dom = new DomDocument();
//load the html into the object
$dom->loadHTML($html);
//discard white space
$dom->preserveWhiteSpace = false;
//all input tags as a list
$input_tags = $dom->getElementsByTagName('input');
//get all rows from the table
for ($i = 0; $i < $input_tags->length; $i++) {
if (is_object($input_tags->item($i))) {
$name = $value = '';
$name_o = $input_tags->item($i)->attributes->getNamedItem('name');
if (is_object($name_o)) {
$name = $name_o->value;
$value_o = $input_tags->item($i)->attributes->getNamedItem('value');
if (is_object($value_o)) {
$value = $input_tags->item($i)->attributes->getNamedItem('value')->value;
}
$post_data[$name] = $value;
}
}
}
return $post_data;
}
示例14: areXmlSame
function areXmlSame($xmlString1, $xmlString2)
{
$document1 = new DomDocument();
$document2 = new DomDocument();
$document1->loadXML($xmlString1);
$document2->loadXML($xmlString2);
$allNodes1 = $document1->getElementsByTagName("*");
$allNodes2 = $document2->getElementsByTagName("*");
$length1 = $allNodes1->length;
$length2 = $allNodes2->length;
if ($length1 != $length2) {
return false;
}
for ($i = 0; $i < $length1; $i++) {
$node1 = $allNodes1->item($i);
$node2 = $allNodes2->item($i);
if (!compareAttributes($node1, $node2)) {
return false;
}
if ($node1->nodeName != $node2->nodeName) {
return false;
}
}
return true;
}
示例15: getMetaTags
public static function getMetaTags($url)
{
$rc = null;
try {
$settings[CURLOPT_URL] = $url;
$contents = self::runCurl($settings);
if (!empty($contents)) {
libxml_use_internal_errors(true);
$doc = new \DomDocument();
$doc->loadHTML($contents);
$metas = $doc->getElementsByTagName('meta');
$rc = array();
foreach ($metas as $meta) {
$name = $meta->getAttribute('name');
if (empty($name)) {
$name = $meta->getAttribute('property');
}
$content = $meta->getAttribute('content');
if (empty($content)) {
$content = $meta->getAttribute('value');
}
if (!empty($name) && !empty($content)) {
$rc[$name] = $content;
}
}
}
return $rc;
} catch (Exception $e) {
return $rc;
}
}