我从SOAP客户端获取结果作为响应。我试图获取此输出并在我的PHP代码中格式化它。现在我想以用户可读格式将此输出写入文件中。它写在一个文件中,但没有任何空格或新行。我尝试使用PHP_EOL和/ n方法,但它没有用。
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;
}
答案 0 :(得分:1)
如果要输出新行,请使用:\ r \ n
如果要输出标签使用:\ t
另外,如果你愿意,可以使用空格。
类似的东西:
echo "EsacoMainGroupCode => ". $obj2->EsacoMainGroupCode . "<br>\r\n";
如果您不想输出<br>
,只需将其从该行中删除即可。
致以最诚挚的问候,