Jump to content

Recommended Posts

I've been struggling with the preg_match function to extract a certain part of HTML from a curl function. Specifically, here is part of the HTML. I want to extract the "14" and the "93%". I tried using something like:

 

preg_match_all('/qualitySurveyGenericBoxHeader(?>[^>]+)>((?>[^<]+))eys/', $file_contents, $matches, PREG_SET_ORDER); to get the string from "quality" upto "Surveys", but it is not working. I am not sure if it is because there are spaces and \n or something to do with what curl is putting out.

 

 

 

<span class="qualitySurveyHeaderLeftColumn">

<span class="qualitySurveyGenericBox">

<span class="qualitySurveyGenericBoxInner qualityOverallRating">

<span class="qualitySurveyGenericBoxHeader"></span>

<span class="qualitySurveyGenericBoxContent">

<h4><span class="value" style="display:none" >5</span><span class="best" style="display:none">5</span><span class="rating" style="display:none">5"</span><span class="votes" style="display:none">14" </span>93%</h4>

<div>

<span>of Dr. Hinkleys patients <strong>would recommend her to friends and family.</strong></span><br />

<span>(based on 14 Surveys)</span>

</div>

</span>

</span>

</span>

Link to comment
https://forums.phpfreaks.com/topic/274424-preg_match_all-question-from-newbie/
Share on other sites

I think this will do what you want:

<h4><span class="value" style="display:none" >5</span><span class="best" style="display:none">5</span><span class="rating" style="display:none">5"</span><span class="votes" style="display:none">(\d+)" </span>(\d+%)</h4>

A more compressed version:

#qualitySurveyGenericBoxContent.*?(\d+)"\s+</span>(\d+%)</h4>#

 

Though, that said: I think you should give the DOMdocument class a proper look for this one. Especially if you want to fetch more data from this page.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.