Click here to Skip to main content
15,908,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I don't know it is possible or not this is new to me. I want to insert data into the database using a word file. I have a table with two column "question" and "answer" and I have a doc file of the question and answer. I want to fetch data and save it on my database.

What I have tried:

I have some logic to store it if I can recognize # or * in a word file. we can do. suppose I want word file like...

*This is Question

*This is Answer

Then maybe we can save it if loop found first * as save as question and second * an answer. anyone know about some code of library which can do it...
Posted
Updated 3-Apr-18 13:07pm

1 solution

First of all, I would try to find another way to get your input. A .doc file is not the easiest format around for just extracting some values.

The method you're trying could work, but I would mark the beginning of the question/answer as wel as the end of the question/answer. And with a combination of characters that is somewhat more distinctive. e.g.
***This is the question***
###This is the answer###

Then with the help of our trusted regular expressions you could try to extract the data.
For instance, to find the question you can use (where the $subject is the text content of your .doc file):
PHP
if (preg_match('/\\*\\*\\*(?P<question>[^*]+)\\*\\*\\*/', $subject, $regs)) {
	$question = $regs[1];
} else {
	$question = "Did not find a question.";
}
For the answer you could use:
PHP
if (preg_match('/###(?P<answer>[^#]+)###/', $subject, $regs)) {
	$answer = $regs[1];
} else {
	$answer = "Did not find an answer.";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900