当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP DOMImplementation hasFeature()用法及代码示例


DOMImplementation::hasFeature()函数是PHP中的内置函数,用于测试DOM实现是否实现了特定函数。

用法:

bool DOMImplementation::hasFeature( string $feature, string $version )

参数:该函数接受上述和以下描述的两个参数:


  • $feature:它指定要测试的函数。
  • $version:它指定要测试的函数的版本号。

返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。

异常:该函数在错误时引发E_STRICT异常。

以下示例说明了PHP中的DOMImplementation::hasFeature()函数:

范例1:

<?php 
  
// Write the feature name 
$featureName1 = "Core"; 
  
// Check if it exists 
$hasFeature1 =  
    DOMImplementation::hasFeature($featureName1, '1.0'); 
if ($hasFeature1) { 
    echo "Has feature $featureName1 module <br>"; 
} 
  
// Write another feature name 
$featureName2 = "XML"; 
  
// Check if it exists 
$hasFeature2 =  
    DOMImplementation::hasFeature($featureName2, '2.0'); 
if ($hasFeature2) { 
    echo "Has feature $featureName2 module <br>"; 
} 
?>  

输出:

Has feature Core module
Has feature XML module

范例2:

<?php 
// Write the feature name 
$featureName1 = "Events"; 
  
// Check if it doesn't exists 
$hasFeature1 =  
    DOMImplementation::hasFeature($featureName1, '1.0'); 
if (!$hasFeature1) { 
    echo "Doesn't have feature $featureName1 module. <br>"; 
} 
  
// Write another feature name 
$featureName2 = "CSS"; 
  
// Check if it doesn't exists 
$hasFeature2 =  
    DOMImplementation::hasFeature($featureName2, '2.0'); 
if (!$hasFeature2) { 
    echo "Doesn't have feature $featureName2 module. <br>"; 
} 
?>  

输出:

Doesn't have feature Events module.
Doesn't have feature CSS module.

参考: https://www.php.net/manual/en/domimplementation.hasfeature.php



相关用法


注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | DOMImplementation hasFeature() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。