I dont understand your requirements but you can try this:

while(( ($contents=fread( $handle, 100 )) != '' )) {

for ($i=0; $i<100; $i++)
{if
{
...
}
else
if{
..
}

}
}

There may be a problem in the last read above.

If you are trying to count the occurance of A,G,C,T in the file using preg_grep 
may be easier.

Regards,
Shinoj.


> To: [email protected]
> From: [email protected]
> Date: Sun, 31 Jan 2010 22:44:00 +0530
> Subject: [TwinCLinG] read and count only limited characters using php script
> 
>  
>                                                                               
>                                     
>                                                       
> Hi All
> the aim is to read and count only 100 characters from input text file 
> containing characters of A, G, C, T....of 500 or more.... The PHP script 
> which I appended here reads all the 500 or whatever is present in the input 
> file. The help which I expect from the forum is to find and correct the 
> mistake by which it can read and count only the limited number of characters 
> to be set as a condition.
> <?php
> $file="co3.txt";
> $handle=fopen($file, 'r');
> $A=0;
> $G=0;
> $C=0;
> $T=0;
> $contents[] = '';
>     while(!feof($handle)) {
>    $contents[] = fread($handle, 100);
> }
> #echo($contents);
>  { $readchar=fgetc($handle);
>   $readchar=strtoupper($readchar);
> for ($i=0; $i<100; $i++)
> {
> #echo ($contents[$i]);
> if($contents[$i] == 'A' )    # && ($A++ <=100))
>  {
>  
>     $A++;
> #   if ( $A++ <= 100 ) {
>     imagefilledrectangle($img, $x1, $y1, $x2, $y2, $green);
> /***to draw an image of thin vertical rectangular line for every characters 
> read and counted which is secondary***/
>     $x1=$x1+6;
>     $x2=$x2+6;
> }
>     else
>     if ($contents[$i] == 'G' )  # ($G++ <=100))
> {
>     $G++;
> #   if ( $G++ <= 100 ) {
>     imagefilledrectangle($img, $x1, $y1, $x2, $y2, $black);
>     $x1=$x1+6;
>     $x2=$x2+6;
> }
>     else
>     if ($contents[$i] == 'C' )  #($C++ <=100))
> {
>     
>     $C++;
> #   if ( $C++ <= 100 ) {
>     imagefilledrectangle($img, $x1, $y1, $x2, $y2, $blue);
>     $x1=$x1+6;
>     $x2=$x2+6;
> }
>     else
>     if ($contents[$i] == 'T' )  #($T++ <=100))
> {
>     $T++;
> #   if ( $T++ <= 100 ) {
>     imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red);
>     $x1=$x1+6;
>     $x2=$x2+6;
> }
> }
> fclose($handle);
> ?>
> I shall appreciate and honor your help.
> with regards
> s.mahalingam
> 
> 
> 
> [Non-text portions of this message have been removed]
> 
> 
> 
> ------------------------------------
> 
> -----------------------------------------------
> Next Meeting as on our Website: http://ilughyd.org.in
> -----------------------------------------------Yahoo! Groups Links
> 
> 
> 
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969

[Non-text portions of this message have been removed]



------------------------------------

-----------------------------------------------
Next Meeting as on our Website: http://ilughyd.org.in
-----------------------------------------------Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ilughyd/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ilughyd/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to