This question looks embarrassingly simple, but I haven\'t been able to find an answer.
What is the PHP equivalent to the following C# line of code?
s
I wonder why no one has mentioned this yet, but you can do an almost equivalent version using escape sequences in double quoted strings:
\x[0-9A-Fa-f]{1,2}
The sequence of characters matching the regular expression is a character in hexadecimal notation.
ASCII example:
Hello World!
So for your case, all you need to do is $str = "\x30\xA2";
. But these are bytes, not characters. The byte representation of the Unicode codepoint coincides with UTF-16 big endian, so we could print it out directly as such:
ア
If you are using a different encoding, you'll need alter the bytes accordingly (mostly done with a library, though possible by hand too).
UTF-16 little endian example:
ア
UTF-8 example:
ア
There is also the pack function, but you can expect it to be slow.