0

I have a .tex file that I need to parse in order to extract some useful data from it. My idea was to load the .tex file in a string and then work with the string.

The problem is that it is a big file and applying regex on that can be problematic.

What do you thik is the best solution for that? Converting this .tex file in html? Or another format that is easier to deal with?

Thank you.

8
  • What do you mean with big? A few mb? Commented Dec 3, 2013 at 8:17
  • If the file contains normalized data and the records are separated by line breaks, read every line and apply your regex on that. Commented Dec 3, 2013 at 8:17
  • @Philipp, no, the file has about 300 lines on it, it is quiet small in size, but a lot for a string. Commented Dec 3, 2013 at 8:22
  • @TiMESPLiNTER, the file is normalized by TEX and the data are separated with one or multiple line breaks. Commented Dec 3, 2013 at 8:23
  • That isn't big - you could use your regex directly on that 300 lines. Commented Dec 3, 2013 at 8:24

1 Answer 1

2

There is PHP function called fgets https://www.php.net/fgets which you can read the file line by line.

I hope it might be useful.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 for you, this solution seams interesting. Now, I will have to apply multiple regex on the file because at the end I need to parse all. Should I make a switch - case solution and find which data I found?
If you want to normalize the data you can create an array of strings and while reading line by line, search on the array if the line is equal to it.
How do you mean that vahnevileyes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.