vkotrappa Posted February 13, 2013 Share Posted February 13, 2013 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 More sharing options...
scootstah Posted February 13, 2013 Share Posted February 13, 2013 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> Link to comment https://forums.phpfreaks.com/topic/274424-preg_match_all-question-from-newbie/#findComment-1412133 Share on other sites More sharing options...
Christian F. Posted February 14, 2013 Share Posted February 14, 2013 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. Link to comment https://forums.phpfreaks.com/topic/274424-preg_match_all-question-from-newbie/#findComment-1412441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.