Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
/*
26
檢視檔案的16進位內容
27
*/
28
 
29
#如果沒有指定檔案參數
30
if(!isset($_SERVER["argv"][1]))
31
{
32
	echo "檔案參數是必須的".PHP_EOL;
33
	exit;
34
 
35
}#if end
36
 
37
#如果沒有指定檔案參數
38
if(!isset($_SERVER["argv"][2]))
39
{
40
	#預設一次讀取 32 bytes.
41
	$bytes=32;
42
 
43
}#if end
44
 
45
#反之
46
else
47
{
48
	#預設一次讀取 32 bytes.
49
	$bytes=(int)$_SERVER["argv"][2];
50
 
51
}#else end
52
 
53
#預設的space
54
$space=" ";
55
 
56
#預設的PHP_EOL
57
$PHP_EOL=PHP_EOL;
58
 
59
#如果一次讀取的大小為0bytes
60
if($bytes===0)
61
{
62
	#空格變成空字串
63
	$space="";
64
 
65
	#換行變成空字串
66
	$PHP_EOL="";
67
 
68
	#一次讀取1024bytes
69
	$bytes="1024";
70
 
71
}#if end
72
 
73
$i=0;
74
 
75
$fh=fopen($_SERVER["argv"][1],"r");
76
while(!feof($fh))
77
{
78
	$next=fread($fh,$bytes);
79
 
80
	#該行的內容
81
	$line="";
82
 
83
	$line=$line.$PHP_EOL;
84
 
85
	#如果要整齊印出
86
	if($space!=="")
87
	{
88
		$line=$line.strtoupper(sprintf("%08s",base_convert($bytes*$i,10,16))).$space;
89
		$line=$line.strtoupper(sprintf("%08s",$bytes*$i)).$space;
90
	}
91
 
92
	for($j=0;$j<strlen($next);$j++)
93
	{
94
		$line=$line.strtoupper(sprintf("%02s",base_convert(ord($next[$j]),10,16))).$space;
95
	}	
96
 
97
	#移除不必要的符號再印出
98
	echo $line;
99
 
100
	#計數+1
101
	$i++;
102
}
103
?>