0

I'm trying to open a file where the ending of it looks something like this:

 <tags/>
        <workout><Warmup Duration="300" PowerHigh="0.5" PowerLow="0.4"></Warmup>
<SteadyState Duration="300" Power="0.65"></SteadyState>
<SteadyState Duration="30" Power="0.65"></SteadyState>
<SteadyState Duration="570" Power="0.85"></SteadyState>
</workout>
        </workout_file>

But that part isn't read when importing it. Tried several different solutions. Ideally I'd like it to show up as:

300 seconds at 0.65.
30 seconds at 0.65.
570 seconds at 0.85.

I have tried reading the entire text file, but it doesn't read the parts after <tags'/> and I've also tried preg_match to get the text inside the workout elements.

$text1 = file_get_contents("workoutfile.zwo");

preg_match("'<workout>(.*?).</workout>'si", $text1, $wotext);
print_r($wotext[0]);
Martin
  • 15
  • 5
  • 1
    There are much better tools than regex to parse XML: https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php/3577662#3577662 – Jacob Mulquin Dec 18 '21 at 21:45
  • 1
    `file_get_contents()` will always read the entire file. Are you displaying the output on an HTML page? The browser may not be rendering the XML -- use `View Source` to see what's actually being printed. – Barmar Dec 18 '21 at 22:34
  • @Barmar Great tip. It's actually being printed, but nothing shows up on the PHP page. Just empty rows. – Martin Dec 18 '21 at 22:46

0 Answers0