User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,773 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,537 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 8720 | Replies: 7
Reply
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

how to format the form textarea?

  #1  
Jun 16th, 2005
I created a from which includes a textarea, this data will be saved to mysql, when I retrieve it, I want to only display the first two lines of this textarea data(ignore the rest), and only limit to text format(not html), how can I do that?

If I continue to type in textarea without hit return, it will show a long string after retrieving from mysql, I want to know how to control the display format.

thanks for any help.

michael
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: how to format the form textarea?

  #2  
Jun 16th, 2005
To remove code tags, check out PHP's strip_tags function.
http://us3.php.net/manual/en/function.strip-tags.php

You can easily parse or split text based on Returns ("\n"), but you are right, if the user does not hit Return, the text will wrap to another line in the textarea, but is actually not a seperate line. All you can do at that point, is break the string into "lines" based on character length. For example, you may figure that about 60 characters make up a line. You could then split the string into 60 character sections. You can even add logic to prevent splitting mid-word. But you still will not have a way to split the string exactly as it appeared in the textarea.

If you really must have this, you may have to use multiple text inputs instead of a textarea. (One text input per line.) This may or may not be an option in your case.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Re: how to format the form textarea?

  #3  
Jun 16th, 2005
Thanks, Troy, I will give it a try.
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Re: how to format the form textarea?

  #4  
Jun 17th, 2005
I have a <textarea></textarea> in this textarea, people can type anything they want, for example:
in <textarea> people will write like;

123456789
abcdefghigk

and save to the database. but when I get it from database and write to the html it become

123456789abcdefghigk


I cannot simply count the character and wrap it, is there a way to use function(if available) to do it?

Thanks
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: how to format the form textarea?

  #5  
Jun 17th, 2005
In the example you show, most likely, the user did in fact hit RETURN between those lines. If you are then displaying back in HTML, the two lines will show as one since in HTML, you have to specifically break a line with an HTML element such as <BR />.

What you can do is, just before displaying the string, use PHP's str_replace() function to replace "\n" with "<br />". I think this will give you what you want.
http://us2.php.net/manual/en/function.str-replace.php
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jul 2004
Posts: 193
Reputation: PoA is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
PoA PoA is offline Offline
Junior Poster

Re: how to format the form textarea?

  #6  
Jun 17th, 2005
Reply With Quote  
Join Date: Sep 2004
Posts: 7
Reputation: mwa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mwa mwa is offline Offline
Newbie Poster

Re: how to format the form textarea?

  #7  
Jul 9th, 2008
I think you would be better off using explode instead of preg_replace..

To make each line (eg; they did hit enter .. ) but just in case, try exploding on spaces if explode on newline failed ...

  1. $entry_array = explode("\n", $_POST['textarea']);
  2.  
  3. if (empty($entry_array)){
  4. $entry_array = explode(" ", $_POST['textarea']);
  5. }
  6.  
  7. foreach ($entry_array as $entry) {
  8. $insert_query = "INSERT `TABLE` VALUES(NULL, '$entry')";
  9. mysql_query("$insert_query");
  10. }
  11.  
Last edited by peter_budo : Jul 10th, 2008 at 9:04 am. Reason: Correcting code tags, not [code language=php] but [code=php]
Reply With Quote  
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 531
Reputation: Shanti Chepuru is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 53
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Pro

Re: how to format the form textarea?

  #8  
Jul 10th, 2008
Hello try this..

  1. <td><?=substr($_POST['textarea'],0,20);?>.....</td>

You can print only some of the content...
Last edited by Shanti Chepuru : Jul 10th, 2008 at 12:14 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC