capturing echo into a variable

后端 未结 3 681
广开言路
广开言路 2020-12-13 09:15

I am calling functions using dynamic function names (something like this)

$unsafeFunctionName = $_POST[\'function_name\'];
$safeFunctionName   = safe($unsafe         


        
3条回答
  •  渐次进展
    2020-12-13 09:45

    In order to use the output value, if present, or the return value if not, you could simply modify your code like this:

    ob_start();
    $return_val = $safeFunctionName();
    $echo_val = ob_get_clean();
    $result = "" . (strlen($echo_val) ? $echo_val : $return_val) . "";
    

提交回复
热议问题