Jiajun Yao

Stay hungry, Stay foolish.

PHP Single Quoted String

Use PHP single quoted string in a case where I should use double quoted string instead


I write a Python Twisted line receiver server, so the server reads one line at a time. Then I write a PHP client to send lines to server.

socket_write($socket, 'it is one line\r\n', strlen);

However, my server can’t receive a whole line and blocked to wait for \r\n


In a single quoted string, escape sequences you might be used to, such as \r or \n, will be output literally as specified rahter than having any special meaning. So my server receive \r\n literally and doesn’t think that it is a new line character.


Change single quotes to double quotes

socket_write($socket, "it is one line\r\n", strlen);