kevinritt Posted April 5, 2009 Share Posted April 5, 2009 I have a form that someone can enter a strikeout count and then print results. What I want the results to show is the number of strikouts as 'K's. So if there were 5 strikouts the result would be KKKKK. Here's what I've got: <form name="Strikeout" method="post" action=""> Josh Beckett<input type="text" name="josh"> </form> <? for ($i=1; $i <=$josh; $i +=1) { $josh[$i] = K } echo "Josh has: " .$josh ?> The results now would show 5KKKKK if I enter 5 in the text box. How can I get just the Ks without the number? Thanks Link to comment https://forums.phpfreaks.com/topic/152693-for-loop-with-results/ Share on other sites More sharing options...
Fruct0se Posted April 5, 2009 Share Posted April 5, 2009 <?php for ($i=1; $i <=$josh; $i +=1) { $strikes .= 'K'; } echo "Josh has: $strikes strikes"; ?> Link to comment https://forums.phpfreaks.com/topic/152693-for-loop-with-results/#findComment-801847 Share on other sites More sharing options...
kevinritt Posted April 5, 2009 Author Share Posted April 5, 2009 That didn't work. It only puts one K in results. Here's a url: http://suffolk.distancecompsci.com/~rittersh/Strikeout/strikeout.php The results show under the form. If I enter 8 I get Josh Bec8KKKKKKKKett I want the Ks but not the 8 Link to comment https://forums.phpfreaks.com/topic/152693-for-loop-with-results/#findComment-801851 Share on other sites More sharing options...
Singod Posted April 5, 2009 Share Posted April 5, 2009 $K = 1; foreach($String as $josh => $K) { echo $K.'<br>'; } Link to comment https://forums.phpfreaks.com/topic/152693-for-loop-with-results/#findComment-801854 Share on other sites More sharing options...
corbin Posted April 5, 2009 Share Posted April 5, 2009 You might want to know about str_repeat. Link to comment https://forums.phpfreaks.com/topic/152693-for-loop-with-results/#findComment-801858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.