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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -