Jump to content

last question for today


Ninjakreborn

Recommended Posts

I know everything is busy, I know theres not a lot of time left for people to answer questions, i just want to askthis final one for the day. In the other post I was asking questions, I set an array with checkboxes, or whatever it's called, then I called the array couldn't get it to work, someone modified my code
[code]
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];
$location = $_POST['location'];
$favorites = $_POST['favorites'];
$username = $_POST['username'];
$verifyusername = $_POST['verifyusername'];
$password = $_POST['password'];
$verifypassword = $_POST['verifypassword'];
$to = "businessman332211@hotmail.com";
$subject = "freelance businessman!";
$body = "
First Name: $firstname
Last Name: $lastname
Age: $age\n";
foreach ($_POST['choices'] as $choices)
     $body .= "Choices: $choices\n";
$body .= "Location: $location
Favorites: $favorites
Username: $username
Verify Username: $verifyusername
Password: $password
Verify Password: $verifypassword
";
?>
[/code]
I have to know some things can someone break down the whole section
[code]
Age: $age\n";
foreach ($_POST['choices'] as $choices)
     $body .= "Choices: $choices\n";
$body .= "Location: $location
[/code]
I know what a foreach statement is. I am confused as to a few things here.
1. The \n I heard was a line feed, when I originally started with php I used this and got errors, replaced it always with <br /> after that and it worked fine. When he gave me this code, I took out the \n and put <br /> and it didn't work, i tried \n and it did and my jaw hit the floor. What is this, how does it work, and like this person here, when I do learn when to use \n, and when do I learn not too. For instance I don't think this could have been done without the \n.
2. Then he put a $body, in the middle of mybody I tried taking it out but it messed it up, why does he have that there, that is my variable named $body, he called it and said
[code]
$body .= Choices: $choices\n
[/code]
and then did that with location, why did he use the same variable that it was inside of what did $body = whatever do in those 2 places to fix my script. I don't understand this.
3. and last I see he used .= in 2 places on the script. I don't understand this, I searched all over, and searched the operators .= doesn't exist, yet it still worked, I know I am missing something I just need help figuring out what, I only ask questions on this forum, after running through dozens of tutorials and trying things out for myself for awhile, I dissected this entire code, it does not work at all unless all the elements he put in there are exactly the way he put them on, this confuses me as to all thes eelements to this script section are vital yet I understand very little ot it. Thanks for the help

Side question-isn't as important but I was wondering when I set up that array it comes up when the thing is checked, then in the email it has the value name, is there anyway to have it say the sentence I have before the value.
By the way the website if you are wondering where the form is, it's at
www.freelancebusinessman.com/test.php
it's only a test, while I lerarn all this stuff and to style the form. Thanks and the first 3 questions are critical, thanks again.
Link to comment
Share on other sites

The person that sent you the code was me.

The ".=" says take the string on the right side of the operator and append it to the variable on the left. It is the same as writing:
[code]<?php
$somvar = 'This is a test';
$somvar = $somvar . ' more testing'; // $somvar is now the value 'This is a test  more testing'
?>[/code]

You can read about the ".=" operator in [a href=\"http://us2.php.net/manual/en/language.operators.string.php\" target=\"_blank\"]this[/a] section of the manual.

The answer to your question about "\n" working or not working depends on where it is used. The "\n" is known as the newline character and is, on some platforms actually two characters ("\r\n"). When the newline character is sent to a text file, the newline character works as we think it should. When it is written to a HTML file which is then displayed via a web browser, the newline character is turned into a space character, since web browsers do not use it to break lines. They use "<br />" and "<p></p>" tags.

As for the $body within you $body.

I ended the assignment of the first string before I started the foreach and then continued it. I really don't care to use the strings that are continued over many lines as, I think, it makes debugging harder.

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.