j.smith1981 Posted September 23, 2011 Share Posted September 23, 2011 I am interested in just this little snippet of code I am writing for a basic TCP socket server in PHP. Just basically goes along the lines of this: <?php $value = ereg_replace("\n\t\r", "", trim($input)).chr(); It's actually regarding the chr() I know actually its nothing to do with the regular expression replace but what does it actually mean to PHP? I mean I am just using it as an output from a socket_read (as that's what $input is assigned to the value of), but what does the char(0) mean? I mean I seem to remember it being knowing the end of a line of data once the clients sent data into the stream PHP looks at chr(0) as the end of the line of data is that the right way of thinking about this logically? Any helps appreciated, trying to explain such a topic on my blog and I am confused about what to say about that one little bit, I know it's not really part of the regular expression but what does it actually do? Again massive thanks in advance for any replies, Jeremy. Quote Link to comment https://forums.phpfreaks.com/topic/247708-chr-concerning-an-ereg_replace-use-of-function-enquiry/ Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 chr expects an ascii code as a parameter, and it will return the corresponding character... in this case, chr(0) is the NULL character... just chr() with nothing inside will most probably throw a warning. Quote Link to comment https://forums.phpfreaks.com/topic/247708-chr-concerning-an-ereg_replace-use-of-function-enquiry/#findComment-1272004 Share on other sites More sharing options...
j.smith1981 Posted September 23, 2011 Author Share Posted September 23, 2011 So in the sense of this being a chat system or server rather, all it's doing is waiting for the user to enter data? Or it would skip through the whole application, if I posted the whole logic that is? Makes sense in a way. Thanks ever so much! Quote Link to comment https://forums.phpfreaks.com/topic/247708-chr-concerning-an-ereg_replace-use-of-function-enquiry/#findComment-1272005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.