Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 619 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/php
<?php

/*
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2024 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
    
*/

/*
檢視檔案的16進位內容
*/

#如果沒有指定檔案參數
if(!isset($_SERVER["argv"][1]))
{
        echo "檔案參數是必須的".PHP_EOL;
        exit;

}#if end

#如果沒有指定檔案參數
if(!isset($_SERVER["argv"][2]))
{
        #預設一次讀取 32 bytes.
        $bytes=32;

}#if end

#反之
else
{
        #預設一次讀取 32 bytes.
        $bytes=(int)$_SERVER["argv"][2];

}#else end

#預設的space
$space=" ";

#預設的PHP_EOL
$PHP_EOL=PHP_EOL;

#如果一次讀取的大小為0bytes
if($bytes===0)
{
        #空格變成空字串
        $space="";
        
        #換行變成空字串
        $PHP_EOL="";
        
        #一次讀取1024bytes
        $bytes="1024";

}#if end

$i=0;

$fh=fopen($_SERVER["argv"][1],"r");
while(!feof($fh))
{
        $next=fread($fh,$bytes);

        #該行的內容
        $line="";

        $line=$line.$PHP_EOL;
        
        #如果要整齊印出
        if($space!=="")
        {
                $line=$line.strtoupper(sprintf("%08s",base_convert($bytes*$i,10,16))).$space;
                $line=$line.strtoupper(sprintf("%08s",$bytes*$i)).$space;
        }
        
        for($j=0;$j<strlen($next);$j++)
        {
                $line=$line.strtoupper(sprintf("%02s",base_convert(ord($next[$j]),10,16))).$space;
        }       
        
        #移除不必要的符號再印出
        echo $line;
        
        #計數+1
        $i++;
}
?>