[英]Identifying Specific Characters from Text Input
原标题 :
读取并计数输入文本文件中仅出现的A,G,C,T有限字符,例如500个字符中只有100个,并使用gd绘制垂直的矩形矩形条形码图像
它仅读取和计数前10个字符并绘制条形码图像,而不是指定的100个字符。
<?php
$file="co3.txt";
$handle=fopen($file, 'r');
$A=0;
$G=0;
$C=0;
$T=0;
$img = imagecreate(850,80);
$white = imagecolorallocate($img, 255,255,255);
$green=imagecolorallocate($img, 0, 128, 0);
$black=imagecolorallocate($img, 0, 0, 0);
$red=imagecolorallocate($img, 255, 0, 0);
$blue=imagecolorallocate($img, 0, 0, 255);
$x1=40;
$y1=40;
$x2=43;
$y2=80;
$contents = '';
#while(( ($contents=fread( $handle, 100)) !='')) {
while(( ($contents=fread($handle, 100)) )) {
for ($i=0; $i<=100; $i++)
{
if($contents[$i] == 'A')
{
$A++;
imagefilledrectangle($img, $x1, $y1, $x2, $y2, $green);
$x1 = $x1+6;
$x2 = $x2+6;
}
else
if($contents[$i] == 'G')
{
$G++;
imagefilledrectangle($img, $x1, $y1, $x2, $y2, $black);
$x1 = $x1+6;
$x2 = $x2+6;
}
else
if($contents[$i] == 'C')
{
$C++;
imagefilledrectangle($img, $x1, $y1, $x2, $y2, $blue);
$x1 = $x1+6;
$x2 = $x2+6;
}
else
if($contents[$i] == 'T')
{
$T++;
imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red);
$x1 = $x1+6;
$x2 = $x2+6;
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
}
}
}
?>
我想您不仅是前10个字母,还算是找到T的程度。 然后,放错位置的代码片段将产生该图像或该图像。 循环可能会持续到100,可能还会产生更多的图像(每个新的T),但是在这种情况下我不知道PHP的行为,因为一些HTTP响应很容易编写...
或者,您可能会看到这些图像的最后一个 。 无论如何,通过修复放错了位置的东西
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
事情应该开始看起来像预期的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.