Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
Display foreach in PHP

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

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

you should to write this line as following

$aaa="{$file_num}. Hello my name is " . $fileline . " hoho \n";

Just omit the : after is.

over 4 years ago · Santiago Trujillo Report

0

File function return an array with the line ending : see documentation

2 solutions :

  • use FILE_IGNORE_NEW_LINES flag
  • use rtrim in your $fileline
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!