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 Quote Link to comment 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 Quote Link to comment 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); ?> Quote Link to comment 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". Quote Link to comment 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 /> Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.