PHP: Handy little Snippet for Multiline Text Box


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?
  2. // Get the message String
  3. $rawString = $_POST['comments'];
  4.  
  5. // Split the string into pieces for processing
  6. $pieces = explode("\n", $rawString);
  7.  
  8. // First element is the subject line
  9. $subject = $pieces[0];
  10.  
  11. // Take the array, delete the first entry, So we can pass it to $message
  12. $messagePieces = array_slice($pieces, 1);
  13.  
  14. // Replace the \n or add a <br /> if you like.
  15. $message = implode("<br />", $messagePieces);
  16. echo "Subject: ". $subject;
  17. echo "<br />";
  18. echo "Message: ". $message;
  19. ?>
  20. <form action="<? echo $_SERVER['php_self'] ?>" method="post">
  21. <textarea id="comments" name="comments">Your message</textarea>
  22. <input name="send" type="submit" value="Send" />
  23. </form>

URL: http://www.adampatterson.ca/blog/2010/09/php-handy-little-snippet-for-multiline-text-box/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.