I didn't feel the need to reference the rest of the code as you had already posted it previously, this was simply a potential replacement for the function in that code. Since there was only one function in use, it seemed obvious to me that would be the one to replace. I did finish, thanks to the rest of the code already existing due to your post.

As for the javascript, he asked for it in PHP, not JS. But for your satisfaction:
Code: 
var str = 'some string';
str = str.replace(/./g, function(c) { return '\\x' + c.charCodeAt(0).toString(16); });
// str now contains the characters using '\x' notation
However, it won't evaluate the characters. This is due to the '\\x' being evaluated first in the return statement, then the character code (in hex) separately. Meaning the string will literally contain the '\x' notation.

Doing something like the following would result in the '\x' codes being evaluated, leading to the initial string.
Code: 
str = str.replace(/./g, function(c) { eval("c = '\\x" + c.charCodeAt(0).toString(16) + "';"); return c; });
As for it being tested, there's no need, I know it works from reading the code.
JmZ Reviewed by JmZ on . encode PHP Hi KWWH friends, please i want to know to encode for example word "stream" to "\x73\x74r\x65\x61m" i know how to decode the line by htmlentities and that stuff but i don't know how to encode. thanks in advance Rating: 5