AAARRGH!!! chr being funky!
Moderator: General Moderators
AAARRGH!!! chr being funky!
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?
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?
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: AAARRGH!!! chr being funky!
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!
Yeah, I know...I can find examples of it in a lot of places...but it won't work for me.Jonah Bron wrote:Works fine for me. Maybe there is some INI setting throwing you off. Have to get an answer from the experts.
I've looked around for an ini setting without any luck.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: AAARRGH!!! chr being funky!
By exits the code, you mean like die()?
Re: AAARRGH!!! chr being funky!
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?
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>";
}
?>- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: AAARRGH!!! chr being funky!
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!
What did you test?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.
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);Re: AAARRGH!!! chr being funky!
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.
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.