Marci Marci - 4 months ago 27
PHP Question

PHP Simple HTML DOM Parser with a value split

I am using

PHP
Simple
HTML DOM Parser
to scrape some values from a web site.
I already splitted a variable called
$results
(the format is:
number:number
)
using
.str_replace
but I need to use these two numbers from
$results
individually.
This is my code:

require_once '../simple_html_dom.php';

$html = file_get_html('http://www.betexplorer.com/soccer/belgium/jupiler-league/results/');

$match_dates = $html->find("td[class=last-cell nobr date]"); // we have 1 per match
$titles = $html->find("td[class=first-cell tl]"); // 1 per match
$results = $html->find("td[class=result]"); // 1
$best_bets = $html->find("td[class=odds best-betrate]"); // 1
$odds = $html->find("td[class=odds]"); // 2

$c = $b = 0; // two counters

foreach ($titles as $match) {
echo $match_dates[$c]->innertext." - ".$match->innertext." ".str_replace(':',' ',$results[$c]->innertext)." - ".$best_bets[$c++]->attr['data-odd']." / ".$odds[$b++]->attr['data-odd']." / ".$odds[$b++]->attr['data-odd']."<br/>";
}


So I need to use these two numbers from
$results
individually and I'd like to insert all values into a
table
.
Thanks

Answer

As @splash58 already mentions in a comment, you have to use explode to separate the two values easily.

foreach ($titles as $match) {
    list($num1, $num2) = explode(':', $results[$c]->innertext); // <- explode
    echo $match_dates[$c]->innertext .
         " - ".$match->innertext." ".$num1.':'.$num2 .          // <- example use
         " - ".$best_bets[$c++]->attr['data-odd'] .
         " / ".$odds[$b++]->attr['data-odd'] .
         " / ".$odds[$b++]->attr['data-odd'] .
         "<br/>";
}
Comments