Hướng dẫn check byte string php
Say I have a string in php, that prints out to a text file like this: nÖ§9q1Fª£ How do I get the byte codes of this to my text file rather than the funky ascii characters? asked Feb 26, 2009 at 17:00
Use the ord function http://ca.php.net/ord eg.
answered Feb 26, 2009 at 17:03
GautamGautam 2,0651 gold badge24 silver badges24 bronze badges 2 If You wish to get the string as an array of integer codes, there's a nice one-liner:
Beware, the resulting array is indexed from 1, not from 0! answered Mar 21, 2014 at 14:28
Roman HockeRoman Hocke 4,0971 gold badge19 silver badges34 bronze badges 0 If you are talking about the hex value, this should do for you:
Reference
answered Apr 18, 2013 at 10:26
AdeeAdee 4546 silver badges17 bronze badges 1
answered Feb 26, 2009 at 17:06
Henrik PaulHenrik Paul 66k31 gold badges84 silver badges96 bronze badges (PHP 4 >= 4.4.3, PHP 5 >= 5.1.3, PHP 7, PHP 8) mb_check_encoding — Check if strings are valid for the specified encoding Descriptionmb_check_encoding(array|string|null Parametersvalue The byte stream or array to check. If it is omitted, this function checks all the input from the beginning of the request. Warning As of PHP 8.1.0, omitting this parameter or passing
encoding The expected encoding. Return Values Returns Changelog
How can I get the byte array from some string which can contain numbers, letters and so on? If you are familiar with Java, I am looking for the same functionality of the getBytes() method. I tried a snippet like this one:
but without success, so any kind of help will be appreciated. PS: Why do I need this at all!? Well, I need to send a byte array via fputs() to a server written in Java... dokaspar 7,65714 gold badges67 silver badges93 bronze badges asked May 19, 2009 at 23:49 @Sparr is right, but I guess you expected byte array like
By using
Be careful: the output array is of 1-based index (as it was pointed out in the comment) answered Jul 13, 2012 at 8:22 BronekBronek 10.4k2 gold badges43 silver badges45 bronze badges 2
T = 0x54, h = 0x68, ... You can split the result into two-hex-character chunks if necessary. answered May 20, 2009 at 0:29 SparrSparr 7,37730 silver badges47 bronze badges 7 PHP has no explicit answered Jul 13, 2011 at 11:48 soulmergesoulmerge 71.9k19 gold badges117 silver badges152 bronze badges 0 You could try this:
answered May 19, 2009 at 23:59 karim79karim79 336k66 gold badges410 silver badges405 bronze badges In PHP, strings are bytestreams. What exactly are you trying to do? Re: edit
answered Jun 24, 2009 at 20:30 troelskntroelskn 112k24 gold badges132 silver badges154 bronze badges 0 I found several functions defined in http://tw1.php.net/unpack are very useful. Take byteStr2byteArray() as an example:
answered Feb 13, 2014 at 5:53 1 |