K
K
Konstantin Khairov2016-01-27 16:59:17
CMS
Konstantin Khairov, 2016-01-27 16:59:17

Trouble finding information on CURL page, PHP Devel Studio, help?

And so I will try to describe the problem in as much detail as possible, I wrote a project on PHP Devel Studio so that I would always know the online one server. On the server forum there is a monitoring of the desired game, something like a grabber made in PHP Devel Studio, when you click on the button, it should go to the forum page to find the necessary information there in a certain block.
Here is the code that I put in the button:

global $cookie;



$ch=curl_init();
curl_setopt ($ch, CURLOPT_POST,0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_VERIFYHOST,0);
curl_setopt ($ch, CURLOPT_FAILONERROR,1);
curl_setopt ($ch, CURLOPT_HEADERM, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_URL,'http://forum.pvp.uz');
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
$out=curl_exec($ch);
curl_close($ch);

preg_match_all('#<div style="margin-top: -18px;"><nobr><b>12 / 25</b></nobr></div>#',$out ,$matches);
$online=$matches[1][0];
        c("memo1")->text = $online;

As I understand it, regular expressions are needed to search for the necessary information in the required HTML tag, the online list is displayed there according to the scheme 12/25, that is, there are 12 players out of 25 possible on the server.
The line itself where these numbers are located is here:
<div style="margin-top: -18px;">
              
                <nobr>
                  <b>18 / 25</b>
                </nobr>
              
            </div>

There is a table of several servers, but I need to take only the first line. I've already tried many options, I just can't figure out these regular expressions. Can you advise what the problem is, and whether I am doing this operation correctly at all.
The PHP_CURL.dll library is included!
Maybe someone has already done something similar? And knows what my problem is.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OVK2015, 2016-01-27
@Kaylos

$sourceContent = '<div style="margin-top: -18px;">
              
                <nobr>
                  <b>18 / 25</b>
                </nobr>
              
            </div>';
        $regExpWrapper = "#(?:<nobr>(?:.*)(?:<b>))(.*?)/(.*?)(?:</b>)#s";        

    preg_match($regExpWrapper, $sourceContent, $matches);
    echo iconv("UTF-8", "CP866", $matches[1]." из ".$matches[2]);

For some reason, the forum.pvp.uz server is unavailable for me. Therefore, I won’t be able to check what curl gives.
Here for www.goldcs.ru
$regExpWrapper = "#(?:\"wa-progress\")(?:.*?)(?:</div>(?:.*?)>(.*?)/(.*?)</div>)#s";
    $cURL = curl_init();
    curl_setopt ($cURL, CURLOPT_URL,'www.goldcs.ru');
    
    curl_setopt ($cURL, CURLOPT_RETURNTRANSFER,1);
    curl_setopt ($cURL, CURLOPT_SSL_VERIFYPEER, 0);
    
    $cURLResult = curl_exec($cURL);
    
    curl_close($cURL);		
    preg_match($regExpWrapper, $cURLResult, $matches);		
    echo iconv("UTF-8", "CP866", $matches[1]." из ".$matches[2]);

R
riot26, 2016-01-27
@riot26

$out = '<div style="margin-top: -18px;">
              
                <nobr>
                  <b>18 / 25</b>
                </nobr>
              
            </div>';
preg_match('/<div style="margin-top: -18px;">\s*<nobr>\s*<b>(.*)<\/b>\s*<\/nobr>\s*<\/div>/',$out ,$matches);
var_dump($matches);

cheat sheet for regular expressions
polygon

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question