问题
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