| | |
how to format the form textarea?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2005
Posts: 92
Reputation:
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
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: 92
Reputation:
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
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: 234
Reputation:
Solved Threads: 8
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:
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 10:04 am. Reason: Correcting code tags, not [code language=php] but [code=php]
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 1:14 am.
![]() |
Similar Threads
- How to get datas of 3 months of specified year from database using jsp (JSP)
- Computer wont start up (Windows NT / 2000 / XP)
- Cannot resolve symbol (Java)
- Audio File Matching Program (C++)
Other Threads in the PHP Forum
- Previous Thread: js php question
- Next Thread: Paypal integration with website
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






