Jump to content

preg_match_all question from newbie


vkotrappa

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.