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?

2
  • You wanna do it php or javascript? Commented Mar 6, 2014 at 20:08
  • php [message to short] Commented Mar 6, 2014 at 20:15

1 Answer 1

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];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Regex should not be used to parse HTML. Please see this answer for reference...

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.