php - fgets(STDIN) automatic line break? -
i noticed fgets(stdin) in php
i have code :
if($fd = fopen($filename, "a")){ $message = fgets(stdin); $message = $message.":"; echo $message; //fwrite($fd, $message); fclose($fd); } i try exemple insert @ end of text-file :
helloworld but have :
helloworld : not :
helloworld: is stdin makes automatic line feed ? how remove automatic jump ?
use stream_get_line instead of fgets:
if($fd = fopen($filename, "a")){ $message = stream_get_line(stdin, 1024); $message = $message.":"; echo $message; //fwrite($fd, $message); fclose($fd); } or can use rtrim function remove line endings:
if($fd = fopen($filename, "a")){ $message = fgets(stdin); $message = rtrim($message, "\n\r") . ":"; echo $message; //fwrite($fd, $message); fclose($fd); }
Comments
Post a Comment