forked from M1ke/easy-site-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.php
66 lines (60 loc) · 1.44 KB
/
output.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
function csv_output($data, $filename = 'download', $to_screen = false){
$data = strip_tags($data);
if (!empty($filename) and empty($to_screen)){
header('Content-Type: text/csv, charset=utf-8');
header('Content-Disposition: inline; filename="' . $filename . '.csv"');
}
else {
$data = '<pre>' . $data . '</pre>';
if (!empty($filename)){
$data = '<p>File name: ' . $filename . '</p>' . $data;
}
}
echo $data;
die;
}
function echo_array($array, $return = false, $comment = false){
if (!defined('BETA') and empty($_SERVER['SHELL']) and (function_exists('developer') and !developer())){
return '';
}
$html = print_r($array, true);
if (!empty($_SERVER['SHELL']) and !$return){
$html .= PHP_EOL;
}
else {
$html = '<pre>' . htmlspecialchars($html) . '</pre>';
if ($comment){
$html = '<!--' . $html . '-->';
}
}
if ($return){
return $html;
}
echo $html;
return '';
}
function echo_html($html){
echo '<pre>' . htmlspecialchars($html) . '</pre>';
}
function echo_shell($string, $eol = true){
if (PHP_SAPI!=='cli'){
return;
}
if ($string instanceof Exception){
$string = 'E: ' . $string->getMessage();
}
if (is_array($string)){
$string = print_r($string, true);
}
echo $string . ($eol ? PHP_EOL : '');
}
function json_out($data){
header('Content-type: application/json');
$data = json_encode($data);
die($data);
}
function redirect_perm($url = null){
header("HTTP/1.1 301 Moved Permanently");
redirect($url);
}