in php what does $values . mean

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PHPNUStudent
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 1:41 am

in php what does $values . mean

Post by PHPNUStudent »

Hey guys I'm new to PHP check put this code I pieced together:

Code: Select all

 
<?php
 
$BName = @$_POST["btstnme"];
$fName = @$_POST["FirstName"];
$lName = @$_POST["LastName"];
$Adrs = @$_POST["Address"];
$Cty = @$_POST["City"];
$Ste = @$_POST["State"];
$zpc = @$_POST["ZipCode"];
$Phn = @$_POST["Phone"];
$CPh = @$_POST["Cell_Phone"];
$brn = @$_POST["Bank_Routing_Number"];
$ban = @$_POST["Bank_Account_ Number"];
$eml = @$_POST["email"];
 
 
// Set the string to be written to the file
$values = "Bznme: $BName\r\n";
$values = "Name: $fName $lName\r\n";
$values .= "ads: $Adrs\r\n";
$values = "cti: $Cty\r\n";
$values = "sta: $Ste\r\n";
$values .= "zpcd: $zpc\r\n";
$values .= "phnn:  $Phn\r\n";
$values .= "cphnn: $CPh\r\n";
$values .= "bnkrn: $brn\r\n";
$values .= "bacn:  $ban\r\n";
$values =  "envml:  $eml\r\n";
 
 
 
 
// Open the file for truncated writing
$fp = @fopen("organizer.txt", "a") or die("Couldn't open organizer.data for writing!");
$numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!");
 
@fclose($fp);
echo "Wrote $numBytes bytes to organizer.txt successfully!";
 
?> 
 
 

Notice this line $values .= "ads: $Adrs\r\n";
there seems to be a difference when the . is put in front of the $values. I have been trying for several hours, but I cant seem to get all values to write to the txt file. There seems to be a distinct difference between "$values" and "$values ." Can someone tell me what the "." does?? Thanks in advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: in php what does $values . mean

Post by requinix »

. is an operator just like + * - and / - except it works on strings, not numbers. It adds two strings together: "asd" . "123" is the string "asd123".

$x .= $y is shorthand for $x = $x . $y. One $x .= after another pieces $x together one part at a time.

Code: Select all

$x = "abc"; // $x starts off with "abc"
$x .= "def"; // add "def"
$x .= "ghi"; // add "ghi"
$x .= "jkl"; // add "jkl"
 
echo $x; // abcdefghijkl
If you interrupt that pattern with a regular $x = then you start all over again

Code: Select all

$x = "abc"; // $x starts off with "abc"
$x .= "def"; // add "def"
$x .= "ghi"; // add "ghi"
$x .= "jkl"; // add "jkl"
$x = "mno"; // starts over with "mno"
$x .= "pqr"; // add "pqr"
$x .= "stu"; // add "stu" 
 
echo $x; // mnopqrstu
PHPNUStudent
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 1:41 am

Re: in php what does $values . mean

Post by PHPNUStudent »

Sir thanks for your fast reply. I have tried several variations of the $x you mentioned without success. Exactly where does the entry belong - as in the example below..??

$BName = @$_POST["btstnme"];
$fName = @$_POST["FirstName"];
$lName = @$_POST["LastName"];
$Adrs = @$_POST["Address"];
$Cty = @$_POST["City"];
$Ste = @$_POST["State"];
$zpc = @$_POST["ZipCode"];
$Phn = @$_POST["Phone"];
$CPh = @$_POST["Cell_Phone"];
$brn = @$_POST["Bank_Routing_Number"];
$ban = @$_POST["Bank_Account_ Number"];
$eml = @$_POST["email"];


// Set the string to be written to the file
$values = "Bznme: $BName\r\n";
$values = "Name: $fName $lName\r\n";
$values = "ads: $Adrs\r\n";
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: in php what does $values . mean

Post by requinix »

Look at what you had before with the $values. Look at each = and each .= and ask yourself what is going to happen on that line of code. Will $values get set to something (=) or will something be added to it (.=)? Then decide what should happen, and make the changes as you think they should be made.

If this was something that was hard I'd just give the answer, but this is a fundamental of programming - not just with PHP - and you need to learn it if you're going to continue.
PHPNUStudent
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 1:41 am

Re: in php what does $values . mean

Post by PHPNUStudent »

Teach a man to fish I got it. But you should know I have only been fishing for about 36 hours now. Quite frankly time is of the essence - can you assist...??
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: in php what does $values . mean

Post by Grizzzzzzzzzz »

make a seperate php file, write this into it

Code: Select all

 
 
<?php
 
    $string1 = "Will ";
    $string1 .= "The ";
    $string1 = ".= ";
    $string1 .= "operator ";
    $string1 .= "work ";
    $string1 = "like ";
    $string1 = "this? ";
    
    echo $string1;
    
    echo "<BR><BR><BR>";
    
    $string2 = "Will ";
    $string2 .= "The ";
    $string2 .= ".= ";
    $string2 .= "operator ";
    $string2 .= "work ";
    $string2 .= "like ";
    $string2 .= "this? ";
    
    echo $string2;
        
?>
 
 
look at the result.

then look at the code.

then look at the result.

then look at any differences between the 2 pieces of code

then :banghead: :banghead: :banghead:
PHPNUStudent
Forum Newbie
Posts: 4
Joined: Fri Nov 27, 2009 1:41 am

Re: in php what does $values . mean

Post by PHPNUStudent »

Guys forget it - I will try another forum...
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: in php what does $values . mean

Post by iankent »

PHPNUStudent wrote:Guys forget it - I will try another forum...
Why not try learning the language first? As others have said, you're not going to learn anything if you get people to do the work for you. And I'd be surprised if people on other forums will give any more of an answer than you've already had here, seeing as most people share the opinion that its better to teach than to do.

edit:
not only that, but:
PHPNUStudent wrote:Can someone tell me what the "." does?? Thanks in advance.
you've actually had a very specific answer to that question, so what's your problem?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: in php what does $values . mean

Post by jackpf »

PHPNUStudent wrote:Guys forget it - I will try another forum...
I lol'ed.
Post Reply