AAARRGH!!! chr being funky!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elbeau
Forum Newbie
Posts: 4
Joined: Wed Nov 18, 2009 3:45 pm

AAARRGH!!! chr being funky!

Post by elbeau »

OK...I have an array of integers all between 0 and 255. All I want to do is convert them to characters and append them as a string. I know...it's easy...just use chr().

NOT!

When I run my code it will convert all characters <= 127 just fine (regular ascii characters), but it barfs on anything >127. When I say barfs, I mean it just exits the code. It doesn't throw an exception, nothing.

I've found plenty of examples of chr() being used with characters between 128 and 255, but it simply won't work.

This will fail for me: $myvar = chr(185);

Why?

Please...why?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: AAARRGH!!! chr being funky!

Post by Jonah Bron »

Works fine for me. Maybe there is some INI setting throwing you off. Have to get an answer from the experts.
elbeau
Forum Newbie
Posts: 4
Joined: Wed Nov 18, 2009 3:45 pm

Re: AAARRGH!!! chr being funky!

Post by elbeau »

Jonah Bron wrote:Works fine for me. Maybe there is some INI setting throwing you off. Have to get an answer from the experts.
Yeah, I know...I can find examples of it in a lot of places...but it won't work for me.

I've looked around for an ini setting without any luck.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: AAARRGH!!! chr being funky!

Post by Jonah Bron »

By exits the code, you mean like die()?
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: AAARRGH!!! chr being funky!

Post by Weiry »

Can you post the code where your using the loop to display the ascii characters?
There may be an issue in the actual code which is causing it to break.

Have you tried creating a new PHP document, and putting something like the following code in to double check?

Code: Select all

<?php
for($i=32;$i<=255;$i++){
    $chr = chr($i);
    print "{$i}: {$chr}<br>";
}
?>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: AAARRGH!!! chr being funky!

Post by Jonah Bron »

Good point.

Or, even just

Code: Select all

echo chr(255);
elbeau
Forum Newbie
Posts: 4
Joined: Wed Nov 18, 2009 3:45 pm

Re: AAARRGH!!! chr being funky!

Post by elbeau »

Jonah Bron wrote:Good point.

Or, even just

Code: Select all

echo chr(255);

Good call. I tested that alone in a page and it works fine. Now I'm really confused. It's obviously not php's fault.

I'm writing this code as a Joomla component. It's executing inside an object's function. The loop where I'm appending the characters is populated by data the user submits...in this case it's a license key. I can run the loop checking the variable type and value (integer / 185)...but when I try to chr() that variable the function exits without ever getting to the next line of code. The rest of the Joomla component files appear to still execute even after this happens so it's not doing a die.

nuts.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: AAARRGH!!! chr being funky!

Post by Weiry »

elbeau wrote:I tested that alone in a page and it works fine. Now I'm really confused. It's obviously not php's fault.
What did you test?
chr(255) or chr(185) or chr(32)->chr(255)?

Try turning on all error reporting to see if there are any errors actually occuring.

Code: Select all

error_reporting(E_ALL);
elbeau
Forum Newbie
Posts: 4
Joined: Wed Nov 18, 2009 3:45 pm

Re: AAARRGH!!! chr being funky!

Post by elbeau »

OK, I can't tell you for sure what everything was doing, but I found a resolution for myself.

This problem was Joomla related. I can create the characters just fine.

I was using a function in Joomla to debug. This function allowed me to redirect to a page while passing a $msg to display. This $msg variable works fine for regular ascii characters, but Joomla ignores the $msg if it has any characters > 127.

Thanks to everyone who helped.
Post Reply