Reputation: 51
So I am working on a PHP application where a user would be able to store text using a keyword i.e. Keyword "Br" text "Back bone polished". For this particular section the user would be able to edit all of the text they have stored in the database. The information would be presented inside of a standard text area as follows:
Text Area
<textarea rows="15" cols="20" id="inputMulti" wrap="hard" name="inputMulti">
Actual Text inside text area
na "No acute cardiopulmonary abnormality. "
! "Test Bed - Chrome on MacBook Pro.
1. Font is not Courier.
2. Compiler is not working.
3. Buttons are not high-lighting.
4. Edit and Delete buttons not working in Reports.
5. multiple codes "entered" are inappropriately separated by commas, that are carried over from box 1.
6. On Show list page, instead of view, we can just simplify and go straight to edit.
7. Once you Delete a code from the Code View page, you get an Page Not Found error.
8. MRI Code Typer is not linked to Home; and actually, Home doesn't need to be there, the MRI Code Typer 2 would be fine.
9. Box 2 doesn't lengthen as expected; once text field is expanded, "only" a part of it is seen, until additional typing is performed, only then does Box 2 expand properly."
0c "Comparison: unavailable .
FINDINGS:
$$$L,PL,H,B,f0$
IMPRESSION:
$na$
$$"
L """""There is no discernible mass or lobar pneumonia. "
f0 "No displaced fracture or acute osseous deformity is seen. "
The key is before the \t" and the text for the respective key is inside the respective "".
Now what I am trying to do is pull everything in between the respective "". The delima is that I cannot explode by " because the text inside the "" may contain " which would of course cause issues.
I have managed to create a preg_match_all expression as follows.
preg_match_all("/[\t][\"^\a](...*)[\"$\z\n\r]/", $input_lines, $output_array);
Output from Preg Match All
array(
0=> "No acute cardiopulmonary abnormality. "
1=> "Test Bed - Chrome on MacBook Pro.
2=> "Comparison: unavailable .
3=> """""There is no discernible mass or lobar pneumonia. "
4=> "No displaced fracture or acute osseous deformity is seen. "
)
Now this partially works as it grabs the correct text for each line, but if you notice at key 2 it doesn't include all the text in between the "" as it stops after the initial match although it should continue until it reaches the end of the match which expands over several lines.
I have tried to add the s modifier but that only puts all the matches inside one array that isn't broken up by lines. I also tried the m modifier and that doesn't seem to change anything at all.
Upvotes: 1
Views: 62
Reputation: 962
After several tests I think I got it. Try this pattern:
preg_match_all("/\t\"([^\t]*)\"/", $input_lines, $output_array);
The pattern is made to match everything except a tab (which is the separator between the keyword and the text). This will include the newlines in the match, in the case of multiline text. For this I'm considering the text won't have tabs in the middle, i.e. the tabs are only used to separate the keyword from its corresponding text.
Upvotes: 3