本文整理汇总了PHP中DOMDocument::createEntityReference方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::createEntityReference方法的具体用法?PHP DOMDocument::createEntityReference怎么用?PHP DOMDocument::createEntityReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createEntityReference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xsl_splitContrib
function xsl_splitContrib($m)
{
$SEP = ',';
$dom = new DOMDocument();
$root = $dom->createElement('contrib-group');
$txt = $m[0]->textContent;
// contribs não tem tags, ok txt!
//foreach ($m[0]->childNodes as $node) $txt .= $node->nodeValue;
$lst = explode($SEP, $txt);
//for($i=count($lst)-1; $i+1; $i--) {
$ni = count($lst) - 1;
for ($i = 0; $i <= $ni; $i++) {
$name = trim($lst[$i]);
$isCorresp = 0;
$name = preg_replace('/\\*$/', '', $name, 1, $isCorresp);
$node = $dom->createElement('contrib');
// ,$name
$node->setAttribute('contrib-type', 'author');
if ($isCorresp) {
$node->setAttribute('corresp', 'yes');
}
if (preg_match('/^(.+?)\\s+(.+?)$/', $name, $m)) {
$surname = str_replace('-', '‑', $m[1]);
//'‑' copiado como "―"
$given = str_replace('-', '‑', $m[2]);
$node->appendChild($dom->createElement('surname', $surname));
//$node->appendChild( $dom->createTextNode(' ') ); // cuidado é NBSP dá pau! enquanto createTextNode('♣') funciona!
// ver meu comentario em http://stackoverflow.com/a/8867502/287948 (mas resolvido por hora)
$node->appendChild($dom->createEntityReference('nbsp'));
$node->appendChild($dom->createElement('given-names', $given));
// initials
} else {
$node->appendChild($dom->createElement('surname', $name));
}
$root->appendChild($node);
if ($i < $ni) {
// not last
$root->appendChild($dom->createTextNode("{$SEP} "));
}
// menos no last!
}
return $root;
}
示例2: DOMDocument
<?php
$dom = new DOMDocument('1.0');
$ref = $dom->createEntityReference('nbsp');
$dom->appendChild($ref);
echo $dom->saveXML();
示例3: addStatic
/**
* Adds a simpara and a static entity to an existing method declaration.
*
* Hackish but working.
*
* @param DOMDocument $doc The DOMDocument object.
* @param DOMNode $desc The DOMNode for the method description.
* @return boolean true if the method was updated.
*/
function addStatic(DOMDocument $doc, DOMNode $desc)
{
// Check to see if the static entity has already been added.
if ($desc->hasChildNodes()) {
/**
* BAD HACK: This will not work anymore if the
* entity changes.
*/
// The DOMDocument translates the entities on loading.
$staticText = 'This method must be called statically.';
// Get simparas.
$list = $desc->getElementsByTagName('simpara');
for ($i = 0; $i < $list->length; ++$i) {
$node = $list->item($i);
if ($node->hasChildNodes()) {
// Check for the static text.
$child = $node->firstChild;
do {
if ($child instanceof DOMText && trim($child->wholeText) == $staticText) {
return false;
}
} while ($child = $child->nextSibling);
}
}
}
$simpara = $doc->createElement('simpara');
$simpara->appendChild($doc->createTextNode("\n "));
$simpara->appendChild($doc->createEntityReference('static'));
$simpara->appendChild($doc->createTextNode("\n "));
$desc->appendChild($doc->createTextNode(' '));
$desc->appendChild($simpara);
$desc->appendChild($doc->createTextNode("\n "));
return true;
}