I have a sourcecode like this:
<?php
if(isset($_POST['text_boxx'])) {
$aa = $_POST['text_boxx'];
$myFilee = "./SCENARIO/ocstesting-aktif.txt";
$fhh = fopen($myFilee, 'w') or die("can't open file");
fwrite($fhh,$aa);
fclose($fhh);
}
if(isset($myFilee)){
$myFilee2 = "./SCENARIO/ocstesting.txt";
$fhh2 = fopen($myFilee2, 'w') or die("can't open file");
$filer = file('./SCENARIO/ocstesting-aktif.txt');
foreach ($filer as $file_num => $fileline){
$aaa="{$file_num}. Hello my name is: " . $fileline . " hoho \n";
fwrite($fhh2,$aaa);
}
fclose($fhh2);
}
?>
if I input in textbox :
Oki
Dito
I want it appears in web like :
0. Hello my name is Oki hoho
1. Hello my name is Dito hoho
but it appears :
0. Hello my name is: Oki
hoho
1. Hello my name is: Dito hoho
Please anyone can help :( ? Thank You
you should to write this line as following
$aaa="{$file_num}. Hello my name is " . $fileline . " hoho \n";
Just omit the : after is.
File function return an array with the line ending : see documentation
2 solutions :
FILE_IGNORE_NEW_LINES flagrtrim in your $fileline