Reputation: 1581
I need to change my PHP code from: ($a contains parsed text with html tags to which I want to append more data, checking if video links exist, append the echo statement)
$cont = '<div>'.$a.'<br>.'
if (!empty($a->find('object', 0)->data)){
echo '<a target="_blank" href="'.$a->find('object', 0)->data.'">
Play Video</a> ';
}
if (!empty($a->find('object', 1)->data)){
echo '<a target="_blank" href="'.$a->find('object', 1)->data.'">
Play Video</a> ';
}
.'</div>';
I know this is wrong so I need help implementing comparison operators. Something like:
$cont = '<div>.'$a.'<br>'.
($a->find('object', 0)->data > 0 ? '<a target="_blank"
href="'.$a->find('object', 0)->data.'">Play Video</a> ')
($a->find('object', 1)->data > 0 ? '<a target="_blank"
href="'.$a->find('object', 1)->data.'">Play Video</a> ')
.'</div>';
But I get a syntax error "(" by the first $a->find. Is it possible to do something like this?
Upvotes: 0
Views: 639
Reputation: 23787
You have to add the else part introduced by a semicolon:
$cont = '<div>'.$a.'<br>'.
($a->find('object', 0)->data > 0 ? '<a target="_blank"
href="'.$a->find('object', 0)->data.'">Play Video</a> ':'').
($a->find('object', 1)->data > 0 ? '<a target="_blank"
href="'.$a->find('object', 1)->data.'">Play Video</a> ':'') // :'' here
.'</div>';
Upvotes: 1