Ejemplo n.º 1
0
/**
* Return a parsable string representation of a variable
*
* This is function is limited to array/strings/integers
*
* @param	mixed	$var		Variable
* @return	string				PHP code representing the variable
*/
function my_var_export($var)
{
    if (is_array($var)) {
        $lines = array();
        foreach ($var as $k => $v) {
            $lines[] = my_var_export($k) . '=>' . my_var_export($v);
        }
        return 'array(' . implode(',', $lines) . ')';
    } else {
        if (is_string($var)) {
            return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $var) . "'";
        } else {
            return $var;
        }
    }
}
Ejemplo n.º 2
0
function my_var_export($arr)
{
    $tab = "\t\t";
    $str = "array(\n";
    foreach ($arr as $name => $value) {
        $str .= $tab;
        $str .= format_string($name) . "\t=>\t";
        if (is_array($value)) {
            $exp = my_var_export($value);
            $str .= preg_replace('/^/', $tab, $exp) . "\t,\n";
        } elseif (is_object($value)) {
            $exp = var_export($value, true) . "\t,\n";
            $str .= preg_replace('/^/', $tab, $exp);
        } else {
            $str .= format_string($value) . "\t,\n";
        }
    }
    $str .= "\t)\n";
    return $str;
}