•
•
•
•
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
![]() |
•
•
Join Date: Jun 2005
Posts: 85
Reputation:
Rep Power: 4
Solved Threads: 0
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
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
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
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.
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.
•
•
Join Date: Jun 2005
Posts: 85
Reputation:
Rep Power: 4
Solved Threads: 0
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
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
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
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
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
•
•
Join Date: Jul 2004
Posts: 193
Reputation:
Rep Power: 5
Solved Threads: 2
There are tutorials on phpfreaks.com http://www.phpfreaks.com/tutorials/107/0.php
http://www.phpfreaks.com/tutorials/123/0.php
http://www.phpfreaks.com/tutorials/123/0.php
•
•
Join Date: Sep 2004
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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 ...
To make each line (eg; they did hit enter .. ) but just in case, try exploding on spaces if explode on newline failed ...
php Syntax (Toggle Plain Text)
$entry_array = explode("\n", $_POST['textarea']); if (empty($entry_array)){ $entry_array = explode(" ", $_POST['textarea']); } foreach ($entry_array as $entry) { $insert_query = "INSERT `TABLE` VALUES(NULL, '$entry')"; mysql_query("$insert_query"); }
Last edited by peter_budo : Jul 10th, 2008 at 9:04 am. Reason: Correcting code tags, not [code language=php] but [code=php]
•
•
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 531
Reputation:
Rep Power: 2
Solved Threads: 53
Hello try this..
You can print only some of the content...
php Syntax (Toggle Plain Text)
<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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- How to get datas of 3 months of specified year from database using jsp (JSP)
- Computer wont start up (Windows NT / 2000 / XP / 2003)
- Cannot resolve symbol (Java)
- Audio File Matching Program (C++)
Other Threads in the PHP Forum
- Previous Thread: js php question
- Next Thread: Is Online chatting done with php?


Linear Mode