Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda