Here my if condition is showing "new" as output why? I expect "old":
$d = date("Y");
$string = substr($v, 0, 4) . '<br>'; //here string stores 2015
if($string != $d) {
echo "new";
} else {
echo 'old';
}
Why would 2015 be the same as 2015<br> ?
As noted by Gordon, you're comparing two strings, so it's really like this
if ( "2015" == "2015<br>" ) // false
Stop adding the <br> and it probably works
$d = date("Y");
$string = substr($v, 0, 4);
if($string != $d) {
echo "new";
} else {
echo 'old';
}
AH!!! effect to OP by letting him writing: var_dump($string); and then let him look at the output, so he sees it with his own eyes :)var_dump in a HTLM document will parse the break as HTML, but even if you can't see it, doesn't mean it's not present in the stringvar_dump("2015<br>"); -> string(8) "2015 " I think then he should see that 8 can't match with only 2015
var_dump($string);?var_dump($string);only shows you2015. So what is the real output? (From a-z, most times it's something like:string(4) "2015"or so)