Jump to content


Photo

newline into value


  • Please log in to reply
11 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 June 2006 - 12:42 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 RDFrame

RDFrame
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 10 June 2006 - 12:50 PM


Well, just put a "\n" where ever you need it in the string. For example:

$message = $line1 . "\n" . $line2;

But from what you explain, you're looking to word wrap messages? Just use the wordwrap() feature of PHP:

$message = wordwrap($message);

That will split up the message into lines of 75 characters each.

Hope that helps,
Matt


#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 June 2006 - 01:13 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 RDFrame

RDFrame
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 10 June 2006 - 01:24 PM


I'd personally always go with the second one, just for the sake of style.

$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";


#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 June 2006 - 02:11 PM

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

     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);

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 12 June 2006 - 04:02 PM

bump- still need help if anyone has any answers to offer, thanks.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 June 2006 - 04:56 PM

[!--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.

#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 12 June 2006 - 05:12 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#9 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 June 2006 - 05:33 PM

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]

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
?>

~ D Kuang

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 12 June 2006 - 05:38 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 June 2006 - 06:01 PM

My only advice with heredoc is NEVER 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.

#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 12 June 2006 - 06:03 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users