當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。