使用for循环查找字符串位置

For a school project I need to find the position of the string "AAAAAA" in a long string. I need to use a for loop. So far I came up with the following code:

<?php
  $string1 = "TATAGTTTCCTCTCTATAT";

  $string2 = str_repeat("AAAGCCTCAAATCTCTCTAGTAAAAAAGCCTCAAATCTCTCTAGTAAA", 6);
  $count = strlen($string1.=$string2);

  for($i = 0; $i < $count; $i++){
    $string_to_find = $count{$i};
    print(strpos($string_to_find, 'AAAAAA'));
  }
?>

I can't get it to work. What am I doing wrong?

If you are using strpos(), you dont required to use for loop. you can get the results without that.

<?php
$string1 = "TATAGTTTCCTCTCTATAT";
$string_to_find="";
$string2 = str_repeat("AAAGCCTCAAATCTCTCTAGTAAAAAAGCCTCAAATCTCTCTAGTAAA", 6);
$count = strlen($string1.=$string2);

for($i = 0; $i < $count; $i++){
$string_to_find.=$string1{$i};
print(strpos($string_to_find, 'AAAAAA'));
 }
?>

here is the code you can try.

I think doing it with a for/foreach loop is really bad,
anyway, here is your code, changed your code a little, hope it works

<?php
  $string1  = "TATAGTTTCCTCTCTATAT";
  $string2  = str_repeat( "AAAGCCTCAAATCTCTCTAGTAAAAAAGCCTCAAATCTCTCTAGTAAA", 6 );

  $count  = strlen( $string1 .= $string2 );
  $temp   = null;

  foreach( str_split( $string1 ) as $char ) {
    $temp .=  $char;
    if ( ( $pos = strpos( $temp, "AAAAAA" ) ) !== false ) {
      print( $pos." " );
      $temp = null;
    }
  }
?>