473,466 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Parsing text and drop down list values from a string

3 New Member
Hello folks. I am new to these forums and have something, which has been stumping me for little while.

I am using pspell to spellcheck a scrolling textbox (textarea) containing user input.

I analyze each word and rebuild the text string as a combination of correct text (not misspelled) and a drop down list offering suggestions in place of any misspelled words. Pretty common stuff using pspell.

I display the new string so that the user can select a replacement word from the drop down lists. Each drop down list is programatically named as created as <select name="position[$pos]"> with $pos being its actual position in the original text string. Makes it easier to keep track of where the list belongs. All of that works fine.

On to the question... Once the user has selected replacement words and clicks the "Done" submit button, I call the same PHP script again and now have a string, which for example looks like:

How many times did the [big] brown [dog] jump over the [fence]?

Where big, dog and fence are actually the drop down lists with the selections made to correct "bigg", "dogg" and "fense" misspellings respectively.

The question: Using PHP, How can I parse the complete string, resulting in one string with the drop down lists removed and only the text remaining?

i.e. the string would be "How many times did the big brown dog jump over the fence?"

Handling the regular text has presented no problems, but I have been unable to detect and extract the drop down values in between. The obvious problem stems from the drop down lists using html tags to define them.

Any suggestions and/or examples will be greatly appreciated.
Nov 8 '08 #1
3 5843
dlite922
1,584 Recognized Expert Top Contributor
From what I see, you need to grab the values of the select box.

This seems too easy for someone who knows this much. So, why can't you just grab the select values during a post (form submission) ?

If you want the drop downs to have the same name, name them the same except add brackets [] to the end of the name. then you'll find your $_POST['name'] is an array of the values.

Hope that helps,




Dan
Nov 9 '08 #2
jcassan
3 New Member
Considered the option of snagging either $_GET or $_POST variable assignments, but I am still a bit confused as to how to do it, since the variables (and their names) will change dynamically as the input text does. In other words, the number of drop down lists will match the number of misspelled words. So, if there are 10 misspelled words in the the input text, there will be 10 dropdown lists.

The problem I am facing is that unlike typical form submissions where you know the name of any given field (making it easy to snag its value following a post) such as $_GET['myField'], the dynamilcally generated drop down lists will be named as position[x], where x is the misspelled word's position in the original text. For instance, one would be named position[5] if its original misspelled word was found at character position 5.

I am still a little confused as to the best way to track the dynamically created values. If I have several drop down lists created dynamically and their names are position[2], position [5], position [7], etc. they don't follow a numerical order but rather indicate the text positions they should be reinserted to. The final text string needs to be reassembled as [words that aren't misspelled] + [appropriate drop down selection, where a word was misspelled] + [more words that aren't misspelled] + [appropriate drop down selection, where a word was misspelled] + [more words that aren't misspelled], etc. Thought about storing the values in an array, but that won't work either as the process can't access them in the array by either record number [0], [1], [2], etc or by position number as those numbers won't be known values.

Since I don't know how many drop down lists may be created or their exact names, I can't wrap my brain around how to get the selected values AND insert them back into the string in the correct position following the form submission.

I assumed using the "position[x]" naming convention was a good idea as it would tell me where to insert its value back into the string. i.e. If there are 2 correctly spelled words such as "The brown " they end at character count 10. So my corrected drop down selection of "dog" would be named "position[11]", meaning that it would be inserted following the space (character 10) after the n (character 9) in brown.

Seemed like a good idea, but I am still struggling with how to reassemble (in the correct order) the two dynamically changing variable types, 1. Plain text (correctly spelled words) and 2. Drop down list selections for misspelled words.

This is why I was hoping for a way to identify a drop down list within the string and could grab its value (at that point) to merge it into the final string. i.e. Each word would be checked and added to the new string until a drop down list was encountered, then its selected value would be added in and so on, until all words and selected values were merged back into the new string. Then the final string would be passed back to the user in a text box to approve and submit.

As my final rambling, I have tried an explode on the string using a space as the delimiter and it successfully breaks the components into individual word pieces as expected. When I echo or print each separate piece in order, they do display correctly, including the drop down lists and their selected values. This is what led me to believe that they can be identified as drop down lists versus a plain text word. If that is true, I should be able to grab their value when encountered and pass it to the final string.

Hopefully I haven't made this more confusing and will gladly accept any suggestions. I do get the point about getting the values from a post, but am still unclear as to how to know what to query $_GET or $_POST for as the names will be unknown...

Thanks for the advice.
Nov 9 '08 #3
jcassan
3 New Member
Solved this issue...

I worked on it until late last night and came up with two workable options. The first, uses a preg_replace function to identify <select> and </select> options within the text, indicating where a drop down list resides. It then replaces the drop list with its own selected value. Works very well for parsing out the drop down lists in the string. The second solution involves naming each drop down list as position[x], where x is the word position within the string where the misspelled word was found. I can then access the $_POST array for "position" and replace the drop down lists with the appropriate posted value when its position within the string has been reached. Both solutions work well. Still deciding which is best for my application.

Thanks for the advice, it got me going in the right direction.
Nov 10 '08 #4

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

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
3
by: excel_hari | last post by:
Hi, I couldnt locate a Classic ASP group hence posting here. One of my colleagues has designed an intranet site and one of the pages has a drop-down box with close to 300 options. I want to...
1
by: lantamer | last post by:
Hi I need to make script that creates drop-down list from text file (new line in text file – new line in drop-down list). Somebody told me that I should use Ajax and XMLHttpRequest for that, so I...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
2
by: =?Utf-8?B?SlA=?= | last post by:
Hi all. I'm having a problem with a postback issue and I think it's cache related. Here's my setup: I have a web site that has a signup section. This has simple things like name, age, birth...
7
by: Eric Wertman | last post by:
I have a set of files with this kind of content (it's dumped from WebSphere): ]
1
by: bytenut | last post by:
I would like to display two field values in a combo after selecting from the list items... i.e. my drop-down shows two fields from a lookup, but when I select the item, only the first field value is...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.