Jump to content

Recommended Posts


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
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-43991
Share on other sites

Is it better to do it like this

$message = "
Hello this is an example
more words
more words
sentences sentences
lots more words
on 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.
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-43993
Share on other sites

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 like
for 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.
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44003
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44657
Share on other sites

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 = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44668
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44687
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11650-newline-into-value/#findComment-44690
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.