Ninjakreborn Posted June 10, 2006 Share Posted June 10, 2006 How do I enter a newline character into a value, I have a mail function, my $message fields are pretty long and I was wondering how to enter a newline character into it, wherever. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/ Share on other sites More sharing options...
RDFrame Posted June 10, 2006 Share Posted June 10, 2006 Well, just put a "\n" where ever you need it in the string. For example:[code]$message = $line1 . "\n" . $line2;[/code]But from what you explain, you're looking to word wrap messages? Just use the wordwrap() feature of PHP:[code]$message = wordwrap($message);[/code]That will split up the message into lines of 75 characters each.Hope that helps,Matt Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-43991 Share on other sites More sharing options...
Ninjakreborn Posted June 10, 2006 Author Share Posted June 10, 2006 Is it better to do it like this$message = "Hello this is an examplemore wordsmore wordssentences sentenceslots more wordson down for awhile ";That is how I use to do it instead of $message = "Welcome to my website, I hope you are finding";$message .= "your stay here warm and welcoming";And so forth which one is better. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-43993 Share on other sites More sharing options...
RDFrame Posted June 10, 2006 Share Posted June 10, 2006 I'd personally always go with the second one, just for the sake of style.[code]$message = "Hello, and welcome to my web site\n";$message .= "And here is the second line of my message\n";$message .= "And the third line.\n";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-43994 Share on other sites More sharing options...
Ninjakreborn Posted June 10, 2006 Author Share Posted June 10, 2006 I tried that, but it got too messy, what I was wondering is there a way to insert a newline(to show up when it emails) into the email variable likefor instance here is what I have[code] if(!mysql_query($insert)) echo 'The information could not be inserted into the database'; else $name = $_POST['name']; $email = $_POST['email']; $to = 'businessman332211@hotmail.com'; $subject = 'Funny Email Forwards Sign up Notification'; $message = "This is a confirmation to inform you that"; $message .= "you have been signed up to the Funny Email Forwards"; $message .= "Newsletter. If you choose to unsubscribe please visit"; $message .= "The website again to unsubscribe."; $message = wordwrap($message); if(mail($to, $subject, $message)) echo "You have been subscribed successfully<br />"; else echo "There was an error sending an email"; } @mysql_close($connection); $to = "businessman332211@hotmail.com"; $subject = "Funny Email Forwards sign up"; $message = "This is a notification letting you know that {$name} has"; $message .= "signed up to the news letter using {$email}."; $message .= "notification is coming from Funny Email Forwards.com"; $message = wordwrap($message); mail($to, $subject, $message);[/code]The word wrap's weren't there before but I still tried it. But what is happening is before when I did the long message with all of it on the same variable it worked out, but I wanted to do it a more "professional" way. Atleast I think, it's more professional. But now that I am starting to do that, I don't understand how to put in spaces, I have 2 words close together, my email, and notfication are stuck really really close together. I would like any advice on this that would help, also someone told me, AND IT WORKS< that you don't have to close most control structures, I never do any more and it works great, and it is easier to read, and I was told you don't need brackets around if, elseif(whatever, else statements unless you have 2 or more statements attributed with that control structure, that the brackets were to contain the insides but i Started doing it formatted like above, and it seems it's a lot easier for me to understand/read/workon, that is was before I tried figuring out where all my freaking brackets went, I am going to check the manual later for more information on whether it is allowed, and to what degree, and get some recommendations from w3schools, I would like to hear some advice feedback from here on this as well.Also mysql_real_escape_string() was givin to me as advice, is there anything else I could use in it's place or with it to make it safer even more. These are just some general questions I am confused about, I know one has to do with a little mysql but it's still a php function, so to avoid confusion here was a run down of what I was asking.1. How to insert a newline into a variable easier.2. About the control structure and everything, advice/feedback/information, anything anyone wants to offer for clarification purposes.3. Any other functions that can be used to replace mysql_real_escape_string, maybe what it really does, I looked it up, but it's confusing, I don't understand why it's needed, and I see alot of other very, very experience php programmers not using this, but this advice was given to me by someone I really trust, and have a dear friendship with, but I always like double checking, getting other peoples opinions, and everything else.4. Again I am open to any advice about anything now, I was a little passive/aggresive at first, not willing to listen to other advice, but I am not going that route any more, I have other advice about a lot of things I am willing to take from anyone, because I now realize just because I hear advice I don't have to necessarily take it right then or at all, but it's still nice to have the opinions and ideas behind various philosophies, and theories, people's personal styles and related subjects. Any advice appreciated, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44003 Share on other sites More sharing options...
Ninjakreborn Posted June 12, 2006 Author Share Posted June 12, 2006 bump- still need help if anyone has any answers to offer, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44636 Share on other sites More sharing options...
wildteen88 Posted June 12, 2006 Share Posted June 12, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]2. About the control structure and everything, advice/feedback/information, anything anyone wants to offer for clarification purposes.[/quote]I prefer to have my brakets in place that way I know where my code blocks are, but if its small code blocks then I may not include them but most of the time I will put them in. This basically down to personal preference just go with what you like best.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]3. Any other functions that can be used to replace mysql_real_escape_string, maybe what it really does, I looked it up, but it's confusing, I don't understand why it's needed, and I see alot of other very, very experience php programmers not using this, but this advice was given to me by someone I really trust, and have a dear friendship with, but I always like double checking, getting other peoples opinions, and everything else.[/quote]mysql_real_escap_string is only used when inserting data into a mysql database to make the data safe. It basically has the following functions addslashes and htmlspecialchars/htmlentities in one function. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44657 Share on other sites More sharing options...
Ninjakreborn Posted June 12, 2006 Author Share Posted June 12, 2006 Ah that makes sense, I will keep that in mind from now on, thanks for the advice.any more passer byers offering advice is appreciated as well. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44662 Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 IF you don't like things too messy, you can use HEREDOC syntax[a href=\"http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc\" target=\"_blank\"]http://www.php.net/manual/en/language.type....syntax.heredoc[/a][code]<?php$str = <<<EODExample of stringspanning multiple linesusing heredoc syntax.EOD;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44668 Share on other sites More sharing options...
Ninjakreborn Posted June 12, 2006 Author Share Posted June 12, 2006 hmm, I studied heredoc for awhile but never thought I would have a purpose for it, I will keep this in mind, and experiment with it, any other advice opinions, about any of this appreciated as well, thanks for the advice so far. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44672 Share on other sites More sharing options...
wildteen88 Posted June 12, 2006 Share Posted June 12, 2006 My only advice with heredoc is [b]NEVER[/b] indent the closing indentifer as PHP will through an error, so EOD or what ever idenfier you may use must not be indented, it must be at the very beginning of the line on its own.Heredoc is good for echoing large amounts of text rather than using seperate echo statements. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44687 Share on other sites More sharing options...
Ninjakreborn Posted June 12, 2006 Author Share Posted June 12, 2006 Hmm I will look into a few of these ideas, I want advice on something really good advice, I know I have heard some, but honestly what should I do, use brackets or not use brackets with my if/elseif statements, I am wanting to figure out something that is easy to read, pretty to look at, and effective enough to be easy for me to understand as I go. Quote Link to comment https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.