Asday Posted July 6, 2007 Share Posted July 6, 2007 Right, I have a set of code that produces a number. I want to display those numbers as images. I know how to make the images appear. I need to know how to run a piece of code for every number in the string, on each number in the string, such as (VB.NET ish): For Each char As Character in $count194 char(x) offset = x // echo the image (don't worry about this bit, just put a comment like this where it should be) Next Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/ Share on other sites More sharing options...
GingerRobot Posted July 6, 2007 Share Posted July 6, 2007 <?php $mystring = 'foobar'; for($x=0;$x<strlen($mystring);$x++){ echo $mystring[$x].'<br />'; } ?> Produces: f o o b a r Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/#findComment-291222 Share on other sites More sharing options...
Asday Posted July 6, 2007 Author Share Posted July 6, 2007 <?php $mystring = 'foobar'; for($x=0;$x<strlen($mystring);$x++){ echo $mystring[$x].'<br />'; } ?> K, tried that, (with my code, which produces a "1") and the page source was: <br /> My code is this: <?php $fp=fopen("count.txt", "r+b"); $count194=fread($fp, filesize("count.txt")); fclose($fp); unlink("count.txt"); $count194++; for($x=0;$x<strlen($count194);$x++) { echo $count194[$x] . "<br />"; } // echo $count194; touch("count.txt"); $fpNew=fopen("count.txt", "r+b"); fwrite($fpNew, $count194); ?> Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/#findComment-291233 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 $count194++; Why are you adding one to a "string". Thats why it produces "1". Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/#findComment-291236 Share on other sites More sharing options...
Asday Posted July 6, 2007 Author Share Posted July 6, 2007 $count194++; Why are you adding one to a "string". Thats why it produces "1". It's meant to produce "1". The next time it's run, it produces a "2". It's a counter. The original "string" is "0". That's not the problem. The problem is that that code sample only outputs <br /> Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/#findComment-291239 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 Int's are different than strings. Try this to convert that int to a string: $count194++; $count194 = "$count194"; for($x=0;$x<strlen($count194);$x++) { echo $count194[$x] . "<br />"; } See if that works. Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/#findComment-291243 Share on other sites More sharing options...
Asday Posted July 6, 2007 Author Share Posted July 6, 2007 Int's are different than strings. Try this to convert that int to a string: $count194++; $count194 = "$count194"; for($x=0;$x<strlen($count194);$x++) { echo $count194[$x] . "<br />"; } See if that works. Excellent, that works perfectly. I now have images instead of numbers. (^-^ ) Thanks, all! Link to comment https://forums.phpfreaks.com/topic/58718-solved-for-each-character-in-string/#findComment-291254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.