Jump to content

[SOLVED] For each character in string...


Asday

Recommended Posts

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
Share on other sites

<?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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.