Jump to content

Help with in_array() and chr()


thepip3r

Recommended Posts

I have an array $chars that has some of the 256 characters but not all in it (ie abc,ABC,123,!@#, and some of the upper ASCII characters as well) when I try to do an evaluation using in_array(), it always evaluates to true and I can't seem to figure out why; can anyone offer any pointers?

[code]
echo "<table width=\"100%\"><tr>";

for ($i=1; $i<256; $i++) {
if (in_array(chr($i), $chars)) {
if ($i % 10 == 0) {
echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td></tr><tr>";
} else {
echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td>";
}
} else {
if ($i % 10 == 0) {
echo "<td>2 $i: " . chr($i) . "<br /></td></tr><tr>";
} else {
echo "<td>2 $i: " . chr($i) . "<br /></td>";
}
}
}

echo "</tr></table>";[/code]
Link to comment
Share on other sites

what don't you understand??  my array chars looks something like:

[code]
$chars[] = "a";
$chars[] = "b";
$chars[] = "A";
$chars[] = "B";
$chars[] = "!";
$chars[] = "@";
$chars[] = chr(192);
$chars[] = chr(215);

echo "<table width=\"100%\"><tr>";

for ($i=1; $i<256; $i++) {
if (in_array(chr($i), $chars)) {
if ($i % 10 == 0) {
echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td></tr><tr>";
} else {
echo "<td>1 $i: <b>" . chr($i) . "</b><br /></td>";
}
} else {
if ($i % 10 == 0) {
echo "<td>2 $i: " . chr($i) . "<br /></td></tr><tr>";
} else {
echo "<td>2 $i: " . chr($i) . "<br /></td>";
}
}
}

echo "</tr></table>";[/code]

..so I'm looping thorugh 255 out of the 256 chars possible (1-255 (excluding 0 which is null))  to see if they exist in my array.  If they do, it's supposed to enbolden those chars.  If it doesn't, it supposed to format them normally.  Hence the bold tags in the first set of sub-ifs and the non-inclusion of the bold tags in the second sub-if.
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.