我有以下代码:
if(isset($riskTriggerFlag) && $riskTriggerFlag==1) // if risk_mitigator process reads and offer weight is maintained based on offer mentioned.
{
echo "Risk Weight: ".$risk_weight ."\n";
$randNo = rand(1,100);
echo "Random Weight: ". $randNo ."\n";
if($randNo < intval(100 - $risk_weight))
{
$flagThrowPostback = 1;
}
}
正如你所看到的,我正在把文字放在文本中,但仍然是在这件事上印刷的信息:
Risk Weight: 20 Random Weight: 20
我做错了什么?
我不能使用 br tag 或 nl2br(),因为总页面只是 php 页面,而我不是想添加任何 html标记。
broswer上的输出就像这样:
<html>
<head></head>
<body>Multiple row Risk Weight: 20 Random Weight: 20 </body>
</html>
答案 0 :(得分:0)
我认为更好的方法是检查php文件是从CLI还是浏览器执行。如果是来自浏览器,则使用其他新行。
$newline = "<br />";
if (PHP_SAPI === 'cli')
{
// ...
$newline = "\n";
}
if(isset($riskTriggerFlag) && $riskTriggerFlag==1) // if risk_mitigator process reads and offer weight is maintained based on offer mentioned.
{
echo "Risk Weight: ".$risk_weight . $newline;
$randNo = rand(1,100);
echo "Random Weight: ". $randNo . $newline;
if($randNo < intval(100 - $risk_weight))
{
$flagThrowPostback = 1;
}
}