0

I'm using CURL to scrape a progress bar from a website. I already managed to remove everything from the page except the part that I need. It's saved in a array as $progress. This is $progress: <p>Questions Left: <span id="ProgQ">0</span>/25</p>

Now I want to get the get the number 0 in the variable $done and the 25 in the variable #total

I read into this problem, and DOM was suggested, but I'm completly clueless, can anyone explain me step by step how I'm supposed to do this in php?

Dr. Banana
  • 435
  • 1
  • 7
  • 16

1 Answers1

1

In PHP:

$string = '<p>Questions Left: <span id="ProgQ">0</span>/25</p>';
if (preg_match('#<span id="ProgQ">(\d+)</span>/(\d+)#i', $string, $match)) {
   $progress = $match[1];
   $total = $match[2];
}
dikirill
  • 1,873
  • 1
  • 19
  • 21
  • Regex should ***not*** be used to parse HTML. Please see [this](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) answer for reference... – War10ck Mar 06 '14 at 20:12