I have write a code to use html simple dom parser, here it is :
<?php $opts = array( 'http'=>array(
'header'=>"User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53\r\n" ) );
$context = stream_context_create($opts);
set_time_limit(0);
include 'simple_html_dom.php';
$lines = file('BQ.txt');
foreach ($lines as $line_num => $line){
$html = file_get_html($line, false, $context);
if($html && is_object($html) && isset($html->nodes)){
echo $line;
}
echo "<ul>";
foreach($html->find("h1[class='productname'], div[class='productprice']") as $element ){
if ($element) { }
echo "<li>".$element ->plaintext. "</li>";
} else {
echo "kosong"
}
echo "</ul>";
}
$html->clear(); ?>
But it always Parse error: syntax error, unexpected 'else' (T_ELSE) I have tried so many way but still got no solution, the problem is only else{ echo "sorry empty" }
If I run the script without it, it run perfectly
You have syntax error in your code. Please compare your code with below: