hatrickpatrick Posted January 4, 2008 Share Posted January 4, 2008 Lets say, for example, I have a textarea, and into that textarea I type the following Line1 Line2 Line3 Line4 Would there be any way to write a script to put each of those lines into a DB row? The table is called "lines" and the only field is "the_line", apart from the auto increment line_id. In other words, I want PHP to take each line and store it as a DB entry. Another example: This is line 1 This is line 2 And I want my scrupt to take that information and store each line in a seperate DB row. How do I separate the lines into variables? and run htmlentities on each of them first? The textarea name is "testing", for reference... I know this is possible, I've done it before but its been a while and I just can;t remember the code, any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/84395-solved-is-there-any-way-to-separate-lines-in-a-textarea-into-seperate-variables/ Share on other sites More sharing options...
hatrickpatrick Posted January 4, 2008 Author Share Posted January 4, 2008 Never mind, I figured it out - could kick myself for forgetting explode() Quote Link to comment https://forums.phpfreaks.com/topic/84395-solved-is-there-any-way-to-separate-lines-in-a-textarea-into-seperate-variables/#findComment-429869 Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 did you mean like this (does it even work lol.) very bad programming theo.......? <?php $text="line1 line2 line3 line4 line5"; $a=explode(' ',$text); foreach($a as $res){ $res=mysql_resl_esacpe_string($_POST['res']); $sql="INSERT INTO somethink (line1, line2, line3, line4, line5)VALUES('$res')"; $sql_result=mysql_query($sql) or die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84395-solved-is-there-any-way-to-separate-lines-in-a-textarea-into-seperate-variables/#findComment-429878 Share on other sites More sharing options...
CaraRota Posted April 3, 2013 Share Posted April 3, 2013 Im sorry but what if i want also to separate them into /n? How would be the explode()? I want it like this: line1 line2 line3 line4 line5 line6 line7 line8 line9 line10 Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/84395-solved-is-there-any-way-to-separate-lines-in-a-textarea-into-seperate-variables/#findComment-1422652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.