Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chr() function

Status
Not open for further replies.

jianbo

Programmer
Dec 19, 2001
78
US
I tried to print out chr(128)-- chr(255), but the chars showed on screen are totally different from ASCII table.
Chr() only works for tose who are less than 128?
Thanks.
 
On what user interface are you displaying your data?

If HTTP, the display of ASCII characters numerically above 128 will probably be dependent on the characterset your server is sending out.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes, I send data to browser.
What do you mean server side characterset? How can I config it?
The headache thing is that when I choose some special chars from database, it will change to other chars.
Thanks.
 
When your server sends a web page, it will send an HTTP header like:

Content-Type: text/html; charset=ISO-8859-1

The charset sent can be modified within a PHP script, but if one is not specified, your web browser will send its default character set.

I don't know what web server you're using, but on Apache, the default character set is set by the use of the AddDefaultCharSet runtime directive.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Do you have the capability to run this script from a command-line? If so, do yo get the same results as you do when you run it from a web browser?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I get your idea. My OS is WinNT, PHP is under APACHE Web server.
I don't know how to run my PHP under command line. But when I tried to run a VB program to display chr(). It gave the same wrong char as PHP did!
Any more suggestion? Thanks.
 
VB is tied to its OS (Win32), which has tight binding to the user's locale information. It is likely that the VB chr() function changes its output according to the locale settings of the computer on which it is invoked.





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Poke around on your system. It may be that when you installed PHP, an command-line version was installed, too. Is there a php.exe on your system?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Found it. But still got some problem.
I run "php -a" on command line, then type
<?php echo "hi"; ?> , ctrl-D to end input, I got a result "hi".
But if I type <?php echo chr(251); ?>, I got a fatal error.
Any trick here? Thanks.
 
Here is something confuse me. if you check URL: click "HTml codes" button, you get
...
&#223 ß
&#225 á
...
while when you click "ASCII Table" button
you will get 225 ß

Now my problem is I have "ß" char in my database. When I do a selection, system get ß, it think its code is 225, then print out á instead of ß.

Why HTML code doesn't match ASCII code after 127? How can I handle this?
 
Sleipnir214, I submit this as a bug to PHP, and find the actual problem is : in Web server machine, we should in Microsoft SQL server -> Client network Utility -> DB-library Options, uncheck "Automatic ANSI to OEM conversion".
Thanks you for your help, now I know more about PHP :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top