public static function maybe_eval($string) { if (!($string = (string) $string)) { return $string; } // Empty. if (stripos($string, 'php') === FALSE) { return $string; } // Saves time. if (stripos($string, '[php]') !== FALSE) { // PHP shortcode tags? $string = str_ireplace(array('[php]', '[/php]'), array('<?php ', ' ?>'), $string); } if (stripos($string, '< ?php') !== FALSE) { // WP `force_balance_tags()` does this. $string = str_ireplace('< ?php', '<?php ', $string); } // Quick fix here. if (!preg_match('/\\<\\?php\\s/i', $string)) { // String contains PHP tags? return ezphp::convert_excl_tags($string); } // Nothing to evaluate. ob_start(); // Output buffer PHP code execution to collect echo/print calls. eval('?>' . trim($string) . '<?php '); // Evaluate PHP tags (the magic happens here). $string = ob_get_clean(); // Collect output buffer. return ezphp::maybe_strip_md_indents(ezphp::convert_excl_tags($string)); }