在脚本中对文件执行写操作时,我很难将php.
和"
直接转换为php".$VARIABLE."
和\t
格式。我是新来的,所以看起来很混乱。这本书做到了:
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil \t".$sparkqty." spark plugs\t\$".$totalamount."\t". $address."\n";
问题是这些时期和报价的合适位置是什么。由于它们是如何混合在一起的,我不知道它们需要附加到什么上。是否每个变量都需要或它们是否用于之类的选项卡。我想重新排列它,所以有一段字符串,后面跟着一个变量,然后是一个新行。我觉得应该是:
$outputstring = $date."\n\ Tires: ".$tireqty."\n\ Oil: ".$oilqty."\n\ Spark Plugs: ".$sparkqty."\n\$".$totalamount."\n".address."\n";
这样行吗?我要测试的机器上没有php服务器。我希望这有点道理,基本上我不知道所有的标点符号是什么。谢谢。
最佳答案
点(.)是php的连接运算符。在英语中,这意味着它将把线粘在一起。
静态字符串定义为“引用”文本
在php的动态类型中,所有标量(数字、字符串)变量都可以用作字符串
所以…
// 3 static strings
echo "hello" . " " . "world"; // prints 'hello world'
// 2 variables
$a = "hello";
$b = "world";
echo $a . $b ; // prints 'helloworld'; (no space)
// mixed variables and static string
echo $a . " " . $b; // prints 'hello world'
另外,您应该知道单引号(')和双引号(“)字符串之间有区别
单引号是字面意思。
echo '$a $b'; // prints '$a $b' with literal $
echo "$a $b"; // prints 'hello world' where $a and $b are treated as variables