Metin Girişi belirli karakterleri belirleme

1 Cevap

Original title:
to read and count the occurrence of only limited characters of A,G,C,T present in the input text file, for example only 100 out of 500 and draw a thin verticular rectangle barcode images using gd

Bu okuma ve sayar sadece ilk 10 karakter ve bir barkod görüntüsünü çizmek yerine, belirtilen 100 karakter.

<?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);
}

}

}

?>

1 Cevap

Ben sadece seni o kadar çok ilk 10 harf tahmin, ama kulüpler T bulunan noktaya kadar. Sonra, yanlış pasajı bu görüntünün ouptut görüntü üreten. Döngü (her yeni T ile) daha muhtemelen bir kaç görüntüler üreten, 100'e kadar devam edebilir, ancak HTTP yanıt bazı kolayca yazılır beri ben, bu gibi durumlarda PHP davranış bilmiyorum ...

Alternatif last bu görüntülerin görüyor olabilirsiniz. Her neyse, yanlış sabitleyerek

header("Content-type: image/png");
imagepng($img);
imagedestroy($img);

işler beklendiği gibi daha bakmak başlamalıdır.