Vote count:
0
1) How can I remove all numbers, brackets and 's. string' behind the words?
2) If there is a placeholder -- at the begning of the line, the complete keyword should be generated (if the main keyword has pagenumbers it will be added as a keyword itself; if there is no pagenumber behind that, just the following parts are relevant [i.e. Word1 and Word2])
3) It can be possible that a long keyword has a linebreak. This linebreak should be removed (i.e. last line in the example)
Keyword 533 --534
Word1 519, 522
-- any 123
-- another 45, 33
Word2
-- any 23
-- another 5, 3
Keyword 832-- 833,
Keyword 48, 50 -- 51, 527
Keyword (anything)
Keyword s. remove that
Keyword with
linebreak 12, 344
The result should be
Keyword
Word1
any Word1
another Word1
any Word2
another Word2
Keyword
Keyword
Keyword
Keyword
Keyword with linebreak
My attempt:
$myfile = fopen("file.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
$re = "/\\d+(\\s*,\\s*\\d+)*|\\bs\\..*$/im";
$str = fgets($myfile);
$subst = "";
$result = preg_replace($re, $subst, $str);
if (trim($result)) echo trim($result) . "<br>";
}
fclose($myfile);
This works for numbers, commas and the s.-string. But I don't know how to do the thing with the --placeholder and the linebreaks.
asked 1 min ago
Removing numbers and brackets at end of line and fill placeholder at begining of line
Aucun commentaire:
Enregistrer un commentaire