📄 function.domelement-has-attribute.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Checks to see if an attribute exists in the current node</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.domelement-get-elements-by-tagname.html">DomElement->get_elements_by_tagname</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.domelement-remove-attribute.html">DomElement->remove_attribute</a></div> <div class="up"><a href="ref.domxml.html">DOM XML Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.domelement-has-attribute" class="refentry"> <div class="refnamediv"> <h1 class="refname">DomElement->has_attribute</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">DomElement->has_attribute</span> — <span class="dc-title"> Checks to see if an attribute exists in the current node </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="classsynopsis"> <div class="ooclass"><a href="class.domelement.html" class="classname">DomElement</a></div> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>has_attribute</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span> )</div> </div> <p class="para"> This functions checks to see if an attribute named <i><tt class="parameter">name</tt></i> exists in the current node. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">name</tt></i></span> <dd> <p class="para"> The name of the tested attribute. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <b><tt>TRUE</tt></b> if the asked attribute exists, <b><tt>FALSE</tt></b> otherwise. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Testing the existence of an attribute</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">include(</span><span style="color: #DD0000">"example.inc"</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$dom </span><span style="color: #007700">= </span><span style="color: #0000BB">domxml_open_mem</span><span style="color: #007700">(</span><span style="color: #0000BB">$xmlstr</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">"Error while parsing the document\n"</span><span style="color: #007700">;<br /> exit;<br />}<br /><br /></span><span style="color: #0000BB">$root </span><span style="color: #007700">= </span><span style="color: #0000BB">$dom</span><span style="color: #007700">-></span><span style="color: #0000BB">document_element</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$buffer </span><span style="color: #007700">= </span><span style="color: #DD0000">'<html'</span><span style="color: #007700">;<br />if (</span><span style="color: #0000BB">$root</span><span style="color: #007700">-></span><span style="color: #0000BB">has_attribute</span><span style="color: #007700">(</span><span style="color: #DD0000">'language'</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$buffer </span><span style="color: #007700">.= </span><span style="color: #DD0000">'lang="' </span><span style="color: #007700">. </span><span style="color: #0000BB">$root</span><span style="color: #007700">-></span><span style="color: #0000BB">get_attribute</span><span style="color: #007700">(</span><span style="color: #DD0000">'language'</span><span style="color: #007700">) . </span><span style="color: #DD0000">'"'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$buffer </span><span style="color: #007700">.= </span><span style="color: #DD0000">'>'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 migration"> <h3 class="title">Migrating to PHP 5</h3> <p class="para"> Use <a href="domelement.hasattribute.html" class="xref">DOMElement::hasAttribute</a>. </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.domelement-get-elements-by-tagname.html">DomElement->get_elements_by_tagname</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.domelement-remove-attribute.html">DomElement->remove_attribute</a></div> <div class="up"><a href="ref.domxml.html">DOM XML Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -