A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearNon ASCII char in PHP? - page 1
User InfoPosts
Non ASCII char in PHP?#1
I am trying to send something to serial port (r232) with PHP.
I am using this class: http://www.phpclasses.org/browse/package/3679.html

The problem is that I am allowed to send only 1 byte.
But if I send something like "1", I am actually sending 49 (ASCII for 1).
Instead of send("1"), I tried with send(1) but it is no good, because this is integer which has 2 bytes.
So is there a way to send a "real" char, not ASCII equivalent?

posted date: 2009-04-10 13:12:00


Re: Non ASCII char in PHP?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-10 13:12:01


Re: Non ASCII char in PHP?#3
The chr() function returns a character given by the integer for the corresponding ascii character.

posted date: 2009-04-10 13:16:00


Re: Non ASCII char in PHP?#4
It looks like the library is expecting characters as input. If you need to send the character which would encode to 0x01, you just send "\001". The function chr() would convert characters to integer values and would be no use here.One more thing: The byte size of integers depends on the underlying system and is mostly 4 bytes.

posted date: 2009-04-10 13:19:00


Re: Non ASCII char in PHP?#5
Not so. ord() converts characters to integer values, and chr() does the opposite.

posted date: 2009-04-10 13:20:00


Re: Non ASCII char in PHP?#6
I(m not sure what you are trying to accomplish. Are you trying to to send the integer 1? Not being familiar with the class, have you tried to give just the value 1 as an argument? If that doesn(t work, try to wrap it with the chr() function.

posted date: 2009-04-10 13:22:00


Re: Non ASCII char in PHP?#7
It returns a character, but as a PHP string. That won't help the OP

posted date: 2009-04-10 13:53:00


Re: Non ASCII char in PHP?#8
There is no "real character". Computers only understand 0 and 1, not "A", "B" or "C". (Please read the first part of Joel Spolskys nice but way too long Unicode article. It will explain character sets in great detail.)

posted date: 2009-04-11 06:51:00


Re: Non ASCII char in PHP?#9
Doesn't the library take a PHP string? It passes it into fwrite...

posted date: 2009-04-11 12:49:00


Re: Non ASCII char in PHP?#10
To be more precise: chr turns an integer into a byte.

posted date: 2010-03-20 11:20:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.