PHP ouput writing in file in non readable format

久未见 提交于 2019-12-25 03:53:31

问题


I am getting the result from the SOAP client as an response. I tried to get this output and format it in my PHP code. Now I want to write this output in a file in user readable format. It's writing in a file but without any spaces or new lines. I tried with PHP_EOL and /n method but it did not work.

if($parameter['aktion'] == 'getVehicle') 
{ 
    ob_start();
    var_dump(Login());
    $s = ob_get_clean();
     $vehicle = getVehicleValuation();
     $Serial=$vehicle['SerialEquipment'];   
     $VehicleFuel=$vehicle['VehicleFuel'];
     ob_start();

    Ob_start();
     echo "ECE_In=>". $VehicleFuel->ECE_In . "<br>";
         echo "ECE_Out=>". $VehicleFuel->ECE_Out . "<br>";
         echo "ECE_All=>". $VehicleFuel->ECE_All . "<br>";
         echo "ECE_CO2=>". $VehicleFuel->ECE_CO2 . "<br>";                  



       foreach($Serial as $key => $obj)
       {
            echo "<b>"."Serial Equipment=>" . $key . "</b>"."<br>";
            echo "Code=>". $obj->Code . "<br>";
            echo "Desc Short=>". $obj->Desc_Short . "<br>";
            echo "Desc Long=>". $obj->Desc_Long . "<br>";


            foreach($obj->Esaco as $key2 => $obj2)  
            {  
                if($obj2->EsacoMainGroupCode === null){
            // doesn't contain Esaco
            break;
                }
                else{
                  echo "<b>"."Esaco=>" . $key2 . "</b>"."<br>";                 
                echo "EsacoMainGroupCode=>". $obj2->EsacoMainGroupCode . "<br>";
                echo "EsacoMainGroupDesc=>". $obj2->EsacoMainGroupDesc . "<br>";
                echo "EsacoSubGroupCode=>".  $obj2->EsacoSubGroupCode . "<br>";
                echo "EsacoSubGroupCode=>".  $obj2->EsacoSubGroupDesc . "<br>";
                echo "EsacoSubGroupCode=>".  $obj2->EsacoGroupCode . "<br>";
                echo "EsacoSubGroupCode=>".  $obj2->EsacoGroupDesc . "<br>";  
            }       
            }           
         }  
     $content = ob_get_clean(); 
     $file_data = str_replace('<br>', "\n", $content); 
     $file_data = strip_tags($file_data); 
     file_put_contents('/www/1/html/webservices/schwackeNet/result.txt', $file_data); 
     echo $content;
}

回答1:


If you want to output a new line, use: \r\n

if you want to output a tab use :\t

also, use a space if you want.

something like:

 echo "EsacoMainGroupCode => ". $obj2->EsacoMainGroupCode . "<br>\r\n";

if you don't want to output the <br>, just remove it from the line.

Best regards,



来源:https://stackoverflow.com/questions/24934812/php-ouput-writing-in-file-in-non-readable-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!