<?php
$url = "http://www.lolking.net/summoner/euw/20849404";
$str = file_get_contents($url);
if (preg_match('/<ul class="personal_ratings"> ([^<]*)<\/ul>/', $str, $matches) > 0) {
echo $matches[1]; //This is text one
}
?>
Hello guys, I'm trying to extract all the personal ratings info from $url I provided, bur for some reason I can't find a way to extract it like this, I've been trying a ton of different ways but I guess it's my lack of regex knowlede working here, it's probably a small dumb mistake but I've been looking to fix this for the last few days now.
I see few mistakes:
preg_quote()
function or using ~
instead of /
to wrap expression.<ul>
node is split to more than one line of html code, you need to add s
switch.(.*)
with ungreedy switch (U
at the end of expression)I don't have time to check this, but this one should work if site structure is same as in your expression: preg_match('~<ul class="personal_ratings">(.*)</ul>~Us', ...
Anyway, for parsing HTML it is much easier to use some DOM parser, like PHP Simple HTML DOM Parser. It is as easy as:
$html = file_get_html('http://www.lolking.net/summoner/euw/20849404');
$ratings = $html->find('ul.personal_ratings',0)->innertext;
PS. Regex special characters are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -