Revision 5a050f04-d38c-4165-b1e3-bfdc502e3586 - Stack Overflow

My code exist some things like "< i585 >". I wan to get string from "i" to ">". And replace "585" instead of "< i585 >". I write some code in JavaScript.

 <script type="text/javascript">
 var foo ="M <i585> <i646>";
 
 while (foo.indexOf("<i") != -1) {
 
 	var indexBaş = foo.indexOf("<i");
 
 	var indexSon = foo.indexOf(">", indexBaş);
 
 	var id = foo.substring(indexBaş + 2, indexSon);
 
 	foo = foo.substring(0 , indexBaş) + id + foo.substring(indexSon + 1 , foo.lenght);
 				
 }
 document.write(foo);
 </script>

But I have to convert this code to php.
So I write this code

 
 $foo ="M <i585> <i646>";
 
 $start = 0;
 $kacTane= 0;
 
 for($i = 0 ; $i < strlen($foo) ; $i++ ) {
 	if($foo[$i] == "<") {
 		if(($foo + 1 )< strlen($foo)) {
 			if($foo[$i+1] == "i") {
 				$kacTane++;
 			}
 		}
 		
 	}
 }
 
 for($i = 0; $i < $kacTane; $i++) {
 	$ilkIndex = strpos($foo , "<" , $start);
 
 	$sonindex = strpos($foo , ">" , $ilkIndex);
 	
 	$id = substr($foo , $ilkIndex + 2 ,( $sonIndex -3) - $ilkIndex );
 	
 	$first = substr($foo , 0 , $ilkIndex +2);
 	$second = substr($foo , $sonIndex + 1 , strlen($foo) - $sonIndex - 1 );
 	
 	$foo = "$first$id$second";
 	$start = ($sonindex + 1);
 
 }
 echo $foo;

But it isn't work. 

Sorry for bad English.
 

AltStyle によって変換されたページ (->オリジナル) /