I'm having a hard time getting PHP .
and "
straight when doing a write to file in a script. I'm new, so it looks confusing. The book does it:
$outputstring = $date."\t".$tireqty." tires \t".$oilqty." oil \t".$sparkqty." spark plugs\t\$".$totalamount."\t". $address."\n";
The question is what's the appropriate placing for the periods and quotations. Due to how it's all mashed together, I don't know what they need to be attached to. Does each variable need to be ".$VARIABLE."
or are they for the tabs like \t
". I want to rearrange it, so there's a segment of string, followed by a variable, then a new line. What I think it should look like is:
$outputstring = $date."\n\ Tires: ".$tireqty."\n\ Oil: ".$oilqty."\n\ Spark Plugs: ".$sparkqty."\n\$".$totalamount."\n".address."\n";
Would that even work? I don't have a php server on the machine I'm at to test. I hope this makes a little sense, basically I'm not sure what all the punctuation is for. Thanks.
the .
is the concatenation operator in this scenario. So basically the .
stitches together two strings, something like this:
$string = "Hello";
$newString = $string . " World"; // <-- this var now contains "Hello World"
These are all good answers here that should help you understand what's going on, to read more about it you can check out the php manual page:
http://www.php.net/manual/en/language.operators.string.php
All php variables inside double quotes(") gets interpreted:
$var = 'foo';
$var2 = 'bar';
echo "The var content is $var and var2 is $var2";
-- The var content is foo and var2 is bar
If you want to concatenate values you need to do it with dot(.):
echo 'The var content is'.$var.' and var2 is'.$var2;
-- The var content is foo and var2 is bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With