loops - PHP:: Cleaner preg_match_all results -
I am trying to bring a value from the external HTML page.
Now this magic makes me:
preg_match_all ('/ id = "local weather" & gt; (. *?) & Lt; \ / div & gt; ; / ', $ ReturnPage, $ returnValues, PREG_SET_ORDER); But after this line I need to loop the results and clean it.
Why? Because I only need (. *?) and for some reason it is also returned to the additional & lt; / Div & gt; need to close the tag, so I should loop it and clear the array later.
My question is how can I return only this: (. *?) ?
PREG_SET_ORDER to get rid of. Example:
& lt ;? Php $ returnPage = '& lt; Div id = "localWeather" & gt; Exam & lt; / Div & gt; & Lt; Div id = "localWeather" & gt; Test2 & lt; / Div & gt; '; Preg_match_all ('/ id = "localWeather" & gt; (*). & Lt ;? \ / div & gt; /', $ returnPage, $ returnValues); Print_r ($ returnValues); Output:
array ([0] = & gt; array ([0] => ID = "local weather" & gt; Testing & lt; / div & gt; [1] = & gt; id = "local weather"> test2 ) [1] = & gt; array ([0] => ; Exam [1] => test2)) In this case, $ returnValues [1] , divs (and not closing) There is an array of matches with content between, while $ returnValues [0] is an array of whole strings that matches your regex. In addition, regular expressions are not recommended for parsing HTML. I'd rather see the PHP class, it's stronger.
Comments
Post a Comment