John Davidson

html - how to skip InnerText empy in a If statment using php

0 comments
Message:


I am trying to skip when InnerText is empty but it put a default value.


This is my code:


 if (strip_tags($result[$c]->innertext) == '') {
$c++;
continue;
}

This is the output:



Thanks


EDIT2: I did the var_dump


 var_dump($result[$c]->innertext)

and I got this:


how can I fix it please?


EDIT3: This is my code; I extract in this way the names of the teams and the results, but the last one not works in the best way when We have postponed matches


    <?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.betexplorer.com/soccer/japan/j3-league/results/",10);
$html = str_get_html($response);

$titles = $html->find("a[class=in-match]"); // name match
$result = $html->find("td[class=h-text-center]/a"); // result match

$c=0; $b=0; $o=0; $z=0; $h=0; // set counters

foreach ($titles as $match) { //get all data


$match_status = $result[$h++];


if (strip_tags($result[$c]->innertext) == 'POSTP.') { //bypass postponed match but it doesn't work anymore
$c++;
continue;
}

list($num1, $num2) = explode(':', $result[$c++]->innertext); // <- explode
$num1 = intval($num1);
$num2 = intval($num2);
$num3 = ($num1 + $num2);
$risultato = ($num1 . '-' . $num2);

list($home, $away) = explode(' - ', $titles[$z++]->innertext); // <- explode

$home = strip_tags($home);
$away = strip_tags($away);
$matchunit = $home . ' - ' . $away;

echo "<tr><td class='rtitle'>".
"<td> ".$matchunit. "</td> / " . // name match
"<td class='first-cell'>" . $risultato . "</td> " .
"</td></tr><br/>";

} //close foreach
?>


My Answer:
>innerText) != "") {
echo strip_tags($result[$c]->innerText);
} else {
echo "Default Value";
}

Rate this post

5 of 5 based on 3569 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us