如何将此函数的输出存储在变量中?
if (function_exists('qts_language_menu') )
{
qts_language_menu('text');
}
所以,我可以在需要时echo $variable
,即<div>'.$variable.'</div>
if (function_exists('qts_language_menu') ) {
$variable = qts_language_menu('text');
}
您可以这样做(默认值):
$variable = function_exists('qts_language_menu') ? qts_language_menu('text') : "default";
看来,qts_language_menu是一个wordpress'插件函数,不返回值,但直接启用了值。因此,您需要捕获其输出:
if (function_exists('qts_language_menu') )
{
ob_start();
qts_language_menu('text');
$variable = ob_get_clean();
}
尝试此
$variable = "No Data";
if (function_exists('qts_language_menu') )
{
$variable = qts_language_menu('text');
}
echo '<div>'.$variable.'</div>';
You can do it like:
function test(){
if (function_exists('qts_language_menu') ) {return qts_language_menu('text');}
else {return "function doesnot exists";}
}
$result=test();
echo $result;