PHP new一个类的时候多出一个水平制表符是怎么回事

晓敬 2015-05-01 12:04:11

<?php
namespace Org\QRCode;
class QRencode {

public $casesensitive = true;
public $eightbit = false;

public $version = 0;
public $size = 3;
public $margin = 4;

public $structured = 0; // not supported yet

public $level = QRConst::QR_ECLEVEL_L;
public $hint = QRConst::QR_MODE_8;

private function __construct(){

}

//----------------------------------------------------------------------
public static function factory($level = QRConst::QR_ECLEVEL_L, $size = 3, $margin = 4)
{
ob_start();
$enc = new QRencode();
$bom = ob_get_contents();
ob_end_clean();
echo ord($bom[0]);
die(0);
$enc->size = $size;
$enc->margin = $margin;

switch ($level.'') {
case '0':
case '1':
case '2':
case '3':
$enc->level = $level;
break;
case 'l':
case 'L':
$enc->level = QRConst::QR_ECLEVEL_L;
break;
case 'm':
case 'M':
$enc->level = QRConst::QR_ECLEVEL_M;
break;
case 'q':
case 'Q':
$enc->level = QRConst::QR_ECLEVEL_Q;
break;
case 'h':
case 'H':
$enc->level = QRConst::QR_ECLEVEL_H;
break;
}

return $enc;
}

//----------------------------------------------------------------------
public function encodeRAW($intext, $outfile = false)
{
$code = new QRcode();

if($this->eightbit) {
$code->encodeString8bit($intext, $this->version, $this->level);
} else {
$code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
}

return $code->data;
}

//----------------------------------------------------------------------
public function encode($intext, $outfile = false)
{
$code = new QRcode();

if($this->eightbit) {
$code->encodeString8bit($intext, $this->version, $this->level);
} else {
$code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
}

QRtools::markTime('after_encode');

if ($outfile!== false) {
file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
} else {
return QRtools::binarize($code->data);
}
}

//----------------------------------------------------------------------
public function encodePNG($intext, $outfile = false,$saveandprint=false)
{
try {

ob_start();
$tab = $this->encode($intext);
$err = ob_get_contents();
ob_end_clean();

if ($err != '')
QRtools::log($outfile, $err);

$maxSize = (int)(QRConfig::QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));

QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);

} catch (Exception $e) {

QRtools::log($outfile, $e->getMessage());

}
}
}
?>

上面代码在运行到die(0)处的时候多出一个水平制表符来,这个是怎么回事,求各位好友帮忙解答一下,谢谢
PHP版本:PHP Version 5.4.38 x86 用fcgid运行在64位Apache/Win7_64bit上
...全文
274 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2015-05-04
  • 打赏
  • 举报
回复
有可能是你include的文件中有tab输出。
xuzuning 2015-05-04
  • 打赏
  • 举报
回复
1、确保你的这个程序文件是以 无BOM UTF-8 格式存储的 虽然 TP 要求使用 utf-8 字符集,但你你这个程序文件中并没有中文字符,所以保存为 ANSI 也就可以了 2、去掉 QRencode.php 文件中最后一个 ?> (其实本来也没有) 可能是你在编辑他或其相关的文件时,在 <?php ... ?> 之外无意加进了 Tab 键
晓敬 2015-05-04
  • 打赏
  • 举报
回复
引用 4 楼 fdipzone 的回复:
ob_start(); $enc = new QRencode(); $bom = ob_get_contents(); ob_end_clean(); echo ord($bom[0]); die(0); 在die之前,因为执行过ob_end_clean(); 所以在这之前不会有输出的。 你讲的 tab一定就是echo ord($bom[0]); 这里输出的,先注释掉看看。
可能是我没有讲清楚这块流程的作用,之前的程序是:

        $enc = new QRencode();
        $enc->size = $size;
        $enc->margin = $margin;
因为生成图片的时候老是多个类似Bom头的东西,我就开始查,范围缩小到这里的时候发现在了这个东西,只有在new QRencode的时候出来个东西,于是我把这时的内容保存到缓存中打印出缓存中的内容查看,发现是一个ascii为9的水平制表符,我现在不理解类的构造函数中没有任何输出,确自己输出了一个ascii为9的字符是怎么回事。
傲雪星枫 2015-05-02
  • 打赏
  • 举报
回复
ob_start(); $enc = new QRencode(); $bom = ob_get_contents(); ob_end_clean(); echo ord($bom[0]); die(0); 在die之前,因为执行过ob_end_clean(); 所以在这之前不会有输出的。 你讲的 tab一定就是echo ord($bom[0]); 这里输出的,先注释掉看看。
智商众筹 2015-05-02
  • 打赏
  • 举报
回复
引用 2 楼 jingyexiaoyue 的回复:
[quote=引用 1 楼 wander_wind 的回复:] echo ord($bom[0]); 这个是干嘛的
获取缓存中的内容之后,打印出缓存的第一个字符[/quote] 其实我的意思是...你删了它看看是不是它的问题 如果不是,找找直接或间接引用的php脚本,有没有?>后多了一个tab的 php脚本不写?>结尾是个好习惯
晓敬 2015-05-02
  • 打赏
  • 举报
回复
引用 1 楼 wander_wind 的回复:
echo ord($bom[0]); 这个是干嘛的
获取缓存中的内容之后,打印出缓存的第一个字符
智商众筹 2015-05-02
  • 打赏
  • 举报
回复
echo ord($bom[0]); 这个是干嘛的
更新说明: 2017-02-04(yaya) Ls command: Empty Folder returns false. 2016-12-08(yaya) 修正lz4、vhd不显示解压缩进度指示。增加lzma解压缩进度指示。 2016-11-09(不点) 0x8205 bit 5 = 1: 使checkkey闲置循环停止指令。 2016-04-13(yaya) 支持动画菜单 setmenu --graphic-entry=型=菜单行数=菜单列数=图形宽(像素)=图形高(像素)=菜单行间距(像素) 菜单项0的路径文件名 型: 位0:高亮指定颜色 位1:高亮颜色翻转 位2:高亮显示线框 位7:背景透明(最好使用黑色背景) 文件名: *n.??? 格式 n=00-99 高亮颜色由 color HIGHLIGHT=0xrrggbb 指定。 字符可以使用任意字型、字高、颜色,可以辅以图标。 2016-03-25(yaya) 菜单字符可以使用不同字型。 例如:"七" 使用不同字型,将 .hex 文件中的 unicode 码 “4e03” 修改为 “0080”, 将菜单中的 "七" 修改为 “\X0080”。 2016-03-23(yaya) 增强 echo 函数功能。 例如:echo -e \x18 显示 UTF-8 字符 0x18。 echo -e \X2191 显示 unicode 字符 0x2191。 2016-03-15(yaya) 1.增加动画控制热键 F2:播放/停止。 2.增加动画控制位 0x835b,位0:0/1=停止/播放。 3.增加精简字库模式:--simp=起始0,终止0,...,起始3,终止3 中文可以使用 --simp= ,内置字库应当包含 DotSize=[font_h],['simp'] 例如:font --font-high=24 --simp= /24_24.hex DotSize=24,simp 不使用热键: 可以加载 32*32 unifont 全字库 使用热键: 可以加载 24*24 unifont 全字库 使用精简字库: 可以加载 46*46 汉字全字库 使用精简字库及热键:可以加载 40*40 汉字全字库 4.不再支持 bin 格式字库。 2016-03-03(yaya) 1.增加图像背景色设置方法。 splashimage --fill-color=[0xrrggbb] 作用之一,作为小图像的背景。 作用之二,直接作为菜单的背景(即不加载图像背景)。此时只设置字体的前景色即可。 2.增加动画菜单。 splashimage --animated=[type]=[delay]=[last_num]=[x]=[y] START_FILE 型[type]:bit 0-3: 播放次数 bit 4: 永远重复 bit 7: 透明背景 type=00:禁止播放 播放n次:序列图像各显示n次,时间独占。可作为启动前导、序幕。 永远重复:序列图像无限循环,时间与菜单共享。可作为菜单里的动画。 背景透明:即抠像。要求4角像素为背景色。 背景色最好为白色或黑色,这样可以去除一些灰色杂波。若是彩色背景,则应当非常干净。 提醒:请以16进制方式输入。否则易错。 延迟[delay]:序列图像之间的延迟。单位是滴答,即1/18.2秒。 序列数[last_num]:序列图像总数(2位数,从1开始计数)。 偏移[x]、[y]:图像偏移,单位像素。 起始图像文件 START_FILE 命名规则:*n.??? n: 1-9 或 01-99 或 001-999。 3.增加固定图像的背景色可以透明。 splashimage [--offset=[type]=[x]=[y]] FILE 型[type]:bit 7: 透明背景 2016-02-14(yaya) setmenu 函数增加菜单项目背景短/满参数(默认短) 2016-01-19(yaya) splashimage 函数增加图像起始偏移(默认0) 2015-08-20(yaya) 1.支持非

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧