473,761 Members | 5,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extracting individual lines from a Multiline text box for processing

1 New Member
Greetings Master of PHP /bow

I would like to preform the following task but I'm unable to figure out how, I never really got into Arrays and usually just use work arounds. I would be very greatful for your assistance.

1. I want to Copy and Paste data from my computer into a text field (Multiline)

2. When I click submit the php code should then take all of the data from the text field and seperate each line into a seperate variable / array entry.

3. I then need to enter that data into a mysql database (I know how to work with DBs just not the extract from array and enter bit)

I'm not sure if it can be done without an array? I guess you could enter the data into the database on each cycle of the extraction process?

There is no set format to the data, it will look something like this.

French
German
Spanish-Portugal
Chineese

and in my database I would like a field called Language with 1 row per language.

etc...

Thanking you in advance for your help!
Nov 2 '08 #1
1 4711
Atli
5,058 Recognized Expert Expert
Hi.

This is actually quite simple to do once you get used to using arrays.
... Which is true of most things I guess :)

In this case, you can simply split your string into pieces using the explode function. This will create an array, each element containing one piece.

Then you could either use a foreach loop loop to insert each piece into your database.
Or, my personal preference, use the implode function to re-assemble the pieces into a VALUE clause for a single INSERT query.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // This is the string, delimited by a comma, rather than a new-line.
  3. $rawString = "piece1,piece2,piece3";
  4.  
  5. // Split the string into pieces
  6. $pieces = explode(",", $rawString);
  7.  
  8. // Build the top of the INSERT query
  9. $sql = "INSERT INTO `myTable`(`myField`) VALUES\n";
  10.  
  11. // Build the rest of the INSERT query by re-assembling the
  12. // pieces.
  13. $sql .= "('";
  14. $sql .= implode("'), ('", $pieces);
  15. $sql .= "')"; 
  16. ?>
  17.  
Now the $sql variable should be somewhat like:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `myTable`(`myField`) VALUES
  2. ('piece1'), ('piece2'), ('piece3')
  3.  
Be careful tho if this data is coming from a client.
Make sure you run it through the mysql_real_esca pe_string function first, and perhaps even the trim function to.
Nov 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6955
by: lecichy | last post by:
Hello Heres the situation: I got a file with lines like: name:second_name:somenumber:otherinfo etc with different values between colons ( just like passwd file) What I want is to extract some part of it like all names or numbers from each line, simply text fom between e.g. second and third colon. And turn it
5
2956
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past, I have used individual entry fields for each variable. I would now like to use text area boxes to simplify the data entry (this way, data can be produced by another program--FORTRAN, "C", etc.--but analyzed online, so long as it is first...
13
15981
by: Kosio | last post by:
Hello, I know of a way to extract digits from a number using the %10 and divide by 10. But I am wondering if there is an algorithm out there that does not use a divide by 10 feature. The reason I ask is that I am programming on a RISC system where division is quite expensive, and I want to be able to extract the digits from an integer (the integer will be from 1 to 6 digits long, and I know how many digits are in the number).
37
2803
by: Xiao Jianfeng | last post by:
Hi, I need to print a long sting, which is two long so it must expand two lines. I know that we can use backslash(\) to explicitly join two lines into a logical line, but this doesn't work for string literals :( my code: -----------------------------------------------------------------------------
16
10977
by: Preben Randhol | last post by:
Hi A short newbie question. I would like to extract some values from a given text file directly into python variables. Can this be done simply by either standard library or other libraries? Some pointers where to get started would be much appreciated. An example text file: ----------- Some text that can span some lines.
3
1448
by: ad | last post by:
I have set a TextBox to MultiLines and set the rows to 10. I assigned the Text of the TextBox some lins of text at desgin time, but only the first line remain in the TextBox. How can I assign some lines of text at desgin time?
4
6027
by: giddy | last post by:
hi when i run this class i made here , this is what it looks like without text - http://gidsfiles.googlepages.com/LinedTextBox_1.jpg WITH TEXT (heres the issue) - http://gidsfiles.googlepages.com/LinedTextBox_withText.jpg The text turns BOLD and the lines kinda get erased because of the text. perhaps i could overide or handle the onKeydown or somethin and intercept the text to be entered and then draw it myself. Any suggestions????????
6
24157
by: ivan.perak | last post by:
Hello, im a beginner in VB.NET... The thing i would like to do is as it follows.... I have a text file (list of names, every name to the next line) which is about 350000 lines long. I would like to split it and create a new file at every lets say 20000 lines... so, the directory output would have to be something like this:
2
3431
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an array of strings. I am using a multiline textbox to enter new, edit existing, and view the names in the array. This all works well, but now I want to be able to select one more names from the list displayed in the multiline textbox then click a button to copy the selected names into another list so...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.