Page 1 of 1
AAARRGH!!! chr being funky!
Posted: Wed Nov 18, 2009 3:50 pm
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?
Re: AAARRGH!!! chr being funky!
Posted: Wed Nov 18, 2009 4:17 pm
by Jonah Bron
Works fine for me. Maybe there is some INI setting throwing you off. Have to get an answer from the experts.
Re: AAARRGH!!! chr being funky!
Posted: Wed Nov 18, 2009 4:27 pm
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.
Re: AAARRGH!!! chr being funky!
Posted: Wed Nov 18, 2009 4:39 pm
by Jonah Bron
By exits the code, you mean like die()?
Re: AAARRGH!!! chr being funky!
Posted: Wed Nov 18, 2009 4:48 pm
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>";
}
?>
Re: AAARRGH!!! chr being funky!
Posted: Wed Nov 18, 2009 5:13 pm
by Jonah Bron
Good point.
Or, even just
Re: AAARRGH!!! chr being funky!
Posted: Thu Nov 19, 2009 8:07 am
by elbeau
Jonah Bron wrote:Good point.
Or, even just
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.
Re: AAARRGH!!! chr being funky!
Posted: Thu Nov 19, 2009 8:24 am
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.
Re: AAARRGH!!! chr being funky!
Posted: Thu Nov 19, 2009 8:44 am
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.