可能重复:
在php中编写一个函数
我正在使用以下代码
echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled';
Run Code Online (Sandbox Code Playgroud)
这可以启用或禁用它
但我想把函数名称作为函数 _iscurl
然后我可以将其称为跟随我的网站代码中的任何位置
if (_iscurl()){
echo "this is enabled"; // will do an action
}else{
echo "this is disabled"; // will do another action
}
Run Code Online (Sandbox Code Playgroud)
〜谢谢
与我之前的问题几乎相同,检查是否启用了allow_url_fopen
Joh*_* V. 125
只需从函数返回现有支票即可.
function _isCurl(){
return function_exists('curl_version');
}
Run Code Online (Sandbox Code Playgroud)
Ami*_*dey 56
<?php
// Script to test if the CURL extension is installed on this server
// Define function to test
function _is_curl_installed() {
if (in_array ('curl', get_loaded_extensions())) {
return true;
}
else {
return false;
}
}
// Ouput text to user based on test
if (_is_curl_installed()) {
echo "cURL is <span style=\"color:blue\">installed</span> on this server";
} else {
echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}
?>
Run Code Online (Sandbox Code Playgroud)
或者简单的 -
<?
phpinfo();
?>
Run Code Online (Sandbox Code Playgroud)
只是寻找卷曲
来源 - http://www.mattsbits.co.uk/item-164.html
小智 44
var_dump(extension_loaded('curl'));
Run Code Online (Sandbox Code Playgroud)
小智 8
希望这可以帮助.
<?php
function _iscurl() {
return function_exists('curl_version');
}
?>
Run Code Online (Sandbox Code Playgroud)
您可以通过将这些代码放在php文件中进行检查。
<?php
if(in_array ('curl', get_loaded_extensions())) {
echo "CURL is available on your web server";
}
else{
echo "CURL is not available on your web server";
}
Run Code Online (Sandbox Code Playgroud)
要么
var_dump(extension_loaded('curl'));
Run Code Online (Sandbox Code Playgroud)
在您的项目中使用通用的可重用函数总是更好,该函数返回是否加载了扩展。您可以使用以下功能来检查 -
function isExtensionLoaded($extension_name){
return extension_loaded($extension_name);
}
Run Code Online (Sandbox Code Playgroud)
用法
echo isExtensionLoaded('curl');
echo isExtensionLoaded('gd');
Run Code Online (Sandbox Code Playgroud)