How can i write this shortly?
$abc = file_get_contents('one.txt');
if($abc !== '')
{
msg($abc);
} else {
msg('nope');
}
I tried:
$abc = file_get_contents('one.txt');
if($abc !== '') ? msg($abc) : msg('nope');
or
$abc = file_get_contents('one.txt');
msg if($abc !== '') ? $abc : 'nope';
and not working, please help!
You don't use the if
keyword when writing a ternary expression.
($abc != '') ? msg($abc) : msg('nope');
or
msg($abc != '' ? $abc : 'nope');
<?php
msg(($abc = file_get_contents('blah.txt')) ? $abc : 'Nope');
I don't like to suppress errors but maybe:
msg(($abc = @file_get_contents('blah.txt')) ? $abc : 'Nope');