How to extract in an array using Simple HTML Dom

36
February 12, 2019, at 7:20 PM

I am trying to extract some values parsing html from a website. Where are many values with the same tag and when I try to extract them, I got back just "array" word. Obviusly I tried to use class tag to use find and extract I know that I have many values from the same tag, so I should use array to catch them and show on the screen, but I don't know how I can do it.

This is a piece of my html:

    <table cellspacing='0' cellpadding='3' bgcolor='#cccccc' width='100%'>
<tr class='trow3' height='16'><td valign='middle' colspan='3'>
<h2>Juventus vs Frosinone goal statistics</h2>
</td></tr>
<tr class='trow2' height='25'><td align='center' width='42%'><font size='2'><b>Juventus</b></font></td><td align='center' width='16%'></td><td align='center' width='42%'><font size='2'><b>Frosinone</b></font></td></tr>
</table>
<table cellspacing='0' cellpadding='4' bgcolor='#cccccc' width='99%' style='margin-top:6px;'>
<tr class='trow4'><td width='13%' align='center' height='25'>
Home
</td><td width='13%' align='center'>
Total
</td><td width='48%' align='center'>
SCORING
</td><td width='13%' align='center'>Total</td><td width='13%' align='center'>
Away
</td></tr>
<tr class='trow2'><td width='13%' align='center' height='22' bgcolor='#D7EFBE'><b>25</b></td><td width='13%' align='center' bgcolor='#D7EFBE'>49</td><td width='48%' align='center' bgcolor='#D7EFBE'>
Goals scored
</td><td width='13%' align='center' bgcolor='#D7EFBE'>17</td><td width='13%' align='center' bgcolor='#D7EFBE'><b>11</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22' bgcolor='#D7EFBE'><b>2.08</b></td><td width='13%' align='center' bgcolor='#D7EFBE'>2.13</td><td width='48%' align='center' bgcolor='#D7EFBE'>
Goals scored per match
</td><td width='13%' align='center' bgcolor='#D7EFBE'>0.74 </td><td width='13%' align='center' bgcolor='#D7EFBE'><b>0.92</b></td></tr>
<tr class='trow2'><td width='13%' align='center' height='22' bgcolor='#FFCACA'><b>8</b></td><td width='13%' align='center' bgcolor='#FFCACA'>15</td><td width='48%' align='center' bgcolor='#FFCACA'>
Goals conceded
</td><td width='13%' align='center' bgcolor='#FFCACA'>43</td><td width='13%' align='center' bgcolor='#FFCACA'><b>21</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22' bgcolor='#FFCACA'><b>0.67</b></td><td width='13%' align='center' bgcolor='#FFCACA'>0.65</td><td width='48%' align='center' bgcolor='#FFCACA'>
Goals conceded per match
</td><td width='13%' align='center' bgcolor='#FFCACA'>1.87 </td><td width='13%' align='center' bgcolor='#FFCACA'><b>1.75</b></td></tr>
<tr class='trow2'><td width='13%' align='center' height='22'><b>2.75</b></td><td width='13%' align='center'>&nbsp;2.78</td><td width='48%' align='center'>
Scored+conc. per match
</td><td width='13%' align='center'>2.61</td><td width='13%' align='center'><b>2.67</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22'><b>83%</b></td><td width='13%' align='center'>87%</td><td width='48%' align='center'>
Matches over 1.5 goals
</td><td width='13%' align='center'>70%</td><td width='13%' align='center'><b>67%</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22'><b>50%</b></td><td width='13%' align='center'>57%</td><td width='48%' align='center'>
Matches over 2.5 goals
</td><td width='13%' align='center'>48%</td><td width='13%' align='center'><b>58%</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22'><b>25%</b></td><td width='13%' align='center'>22%</td><td width='48%' align='center'>
Matches over 3.5 goals
</td><td width='13%' align='center'>35%</td><td width='13%' align='center'><b>42%</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22'><b>8%</b></td><td width='13%' align='center'>9%</td><td width='48%' align='center'>
Matches over 4.5 goals
</td><td width='13%' align='center'>17%</td><td width='13%' align='center'><b>8%</b></td></tr>
<tr class='trow3'><td width='13%' align='center' height='22'><b>8%</b></td><td width='13%' align='center'>4%</td><td width='48%' align='center'>
Over 2.5 goals at half-time
</td><td width='13%' align='center'>9%</td><td width='13%' align='center'><b>8%</b></td></tr>
</table>
<br>
<table cellspacing='0' cellpadding='3' bgcolor='#cccccc' width='100%'>
<tr class='trow3' height='16'><td valign='middle' colspan='3'>
<h2>Juventus vs Frosinone average scoring</h2>
</td></tr>
</table>
<br>
<table cellspacing='0' cellpadding='1' bgcolor='#cccccc' width='99%'>
<tr class='trow2'><td height='30' colspan='2'>&nbsp;<font size='2' color='blue'>Home scoring averages</font></td></tr>
<tr class='trow3'><td height='18' align='right'><b>Juventus</b> goals scored per match <b>at home</b>&nbsp;</td>
<td align='center'>2.08</td></tr>
<tr class='trow3'><td height='18' align='right'><b>Frosinone</b> goals conceded per match <b>away</b>&nbsp;</td>
<td align='center'>1.75</td></tr>
<tr class='trow2'><td height='22' align='right'>Average&nbsp;</td>
<td align='center'><font color='blue' size='3'><b>1.92</b></font></td></tr>
<tr class='trow3'><td height='18' align='right'><font color='#555555'>League average (home goals per match)&nbsp;</font></td>
<td align='center'><font color='#555555'>1.43</font></td></tr>
</table>

and this is my php code:

    <?php
include('../simple_html_dom.php');
function getHTML($url,$timeout)
{
       $ch = curl_init($url); // initialize curl with given url
       curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set  useragent
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
       curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
       return @curl_exec($ch);
}
$response=getHTML("https://www.soccerstats.com/pmatch.asp?league=italy&stats=631-9-5-2019-juventus-vs-frosinone",10);
$html = str_get_html($response);

$titles = $html->find("tr[class=trow3]/td/h2"); // 1 per match
$team = $html->find("tr[class=trow2]/td/font/b"); // 1 per match
$vediamo = $html->find("tr[class=trow3]/td/b"); // 1 per match
$c=0; $b=0; $o=0; $z=0; // two counters
foreach ($titles as $match) {
 $articles[] = array($vediamo->innertext);
    list($home, $away) = explode(' vs ', $team[$z++]->innertext); // <- explode
echo  "<tr><td class='rtitle'>".
            "<td class='first-cell'>".$match."</td> "  .
            "<td> ".$home.'</td><td> : </td><td>'.$away .  " / " .  // <- example use
                    "<td class='first-cell'>".$articles[0]."</td> "  .

            "</td></tr><br/>";              

        }   //Chiusura ciclo foreach    
?>

I got this result, you can see "array" word

READ ALSO
Best way to combine two tables in php [on hold]

Best way to combine two tables in php [on hold]

I'm working on a project where I want to be able to create a weekly calendar and display shifts for that week next to each employee's name

53
WP Acceptance and the composer.json file required

WP Acceptance and the composer.json file required

I am having trouble setting up WP Acceptance and would like some assistance pleaseIn the documentation it states that it is not required to use WP Local Docker so I have the basic required items installed already

53
Azure AD SSO = AADSTS50020 - multi-tenant, How do I allow external tenants to register to my app?

Azure AD SSO = AADSTS50020 - multi-tenant, How do I allow external tenants to register to my app?

We have a SaaS app and we are integrating with azure ad sso with oauth2 (locally for now) using https://githubcom/TheNetworg/oauth2-azure (v2 common endpoint)

29