PHP标点符号混乱

use*_*571 4 php

在脚本中写入文件时,我很难获得PHP ."直接.我是新人,所以看起来很混乱.这本书做到了:

$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil \t".$sparkqty." spark plugs\t\$".$totalamount."\t". $address."\n";
Run Code Online (Sandbox Code Playgroud)

问题是什么是期间和报价的适当放置.由于它是如何一起捣​​碎的,我不知道它们需要附加什么.每个变量都需要是".$VARIABLE."或者它们是否为\t".我想重新排列它,所以有一段字符串,后跟一个变量,然后是一个新行.我认为它看起来应该是这样的:

$outputstring = $date."\n\ Tires: ".$tireqty."\n\ Oil: ".$oilqty."\n\ Spark Plugs: ".$sparkqty."\n\$".$totalamount."\n".address."\n";
Run Code Online (Sandbox Code Playgroud)

那甚至会起作用吗?我正在测试的机器上没有php服务器.我希望这有点意义,基本上我不确定所有标点符号是什么.谢谢.

A.O*_*.O. 5

.是此场景中的连接运算符.所以基本上.拼凑两个字符串,如下所示:

$string = "Hello";
$newString = $string . " World"; // <-- this var now contains "Hello World"
Run Code Online (Sandbox Code Playgroud)

这些都是很好的答案,可以帮助您了解正在发生的事情,阅读更多相关信息,您可以查看PHP手册页:

http://www.php.net/manual/en/language.operators.string.php


EdC*_*tti 5

双引号(")内的所有php变量都被解释:

$var  = 'foo';
$var2 = 'bar';

echo "The var content is $var and var2 is $var2";
Run Code Online (Sandbox Code Playgroud)

- var内容为foo,var2为bar

如果要连接值,则需要使用点(.)进行连接:

echo 'The var content is'.$var.' and var2 is'.$var2;
Run Code Online (Sandbox Code Playgroud)

- var内容为foo,var2为bar


Ank*_*ise 5

对于双引号你可以在里面添加变量,但我试着在PHP中解决你的cofusion .是一个seprator&'"用于字符串

所以当你使用

$name = 'Sam';
$some_variable = 'THIS IS STRING'[seprator]' OTHER_STRING '[seprator]$name;
Run Code Online (Sandbox Code Playgroud)

所以它会

$some_variable = 'THIS IS STRING'.' OTHER_STRING '.$name;
Run Code Online (Sandbox Code Playgroud)

最终价值将是

$some_variable = 'THIS IS STRING OTHER_STRING Sam';
Run Code Online (Sandbox Code Playgroud)