It doesn’t print that class, which is an anticipated behavior. some issue with the class printing. some syntax issue. because the condition is true. on the same condition, I tried →
style = display: none; and it worked, but it is not printing the class. I do not want to it with style method.
Another thing to point out is that there really is no difference from the second one and the third one other than single quotes and double quotes. I prefer single quotes because double quotes looks really messy. Also, you generally don’t really even need double quotes for anything. If you want to use variables in a string that has a string already, you just concate it like so.
$string = 'My first string ' . $var;
And it would achieve exactly what this does.
$string = "My first string $var";
And if you want to use a single quotation in a string like I haven't really done that, you can simply escape that single quote nested in other single quotes. IMO, double quotes are abused so much in PHP that most people place double quotes in the wrong way possible.
I thought that would cause a problem because the OP already has double-quotes open in their HTML. However it seems that it doesn’t matter. Is this because the parsing for the PHP is separate to the parsing for HTML? Never realised that - I would also have presumed that single quotes were required here.
Not really. The use of double quotes or single quotes doesn’t really matter if the starting of the PHP tag is after the first double quotes. If the class attribute declaration was nested inside another double quote, then escaping is required. But since the output string is enclosed in its own PHP tag, there really is no need for escaping.
I assume it’s because the result isn’t returning the value of none. It might be something else as well. I know that most people also like to use triple equal signs. But in some cases, it might not even work. I remember I tried it a few times using a Boolean value and it never was triggered even though the compared value is exactly the same as the returned value.
I know this is a bit off topic but you really should go back and understand why it was not working in your particular case. Using === bypasses any potential problems that can occur when php silently converts one data type to another. It is well worth the effort to understand the implications of not using it and the kind of errors that could creep in.
Then you don’t need to escape it because if you do echo \"wide-screen\", you’ll have an error of some sort. And if you do <div class=\"small-screen <?php ... ?>\"> then that’s incomplete HTML markup as well.
PHP has “Type juggling” which may introduce errors and it is best to always use ===.
Also and unfortunately the “Type juggling” has a processing overhead resulting in slower processing times.
The latest PHP 7 version introduced optional stricter type checks which result in the language speeding up considerably, some claim as much as a 50% improvement.
If your PHP script is running OK without any problems then try adding these lines at the beginning of the page script. I will be amazed if there are no errors and/or warnings
<?php
// file wide only
declare( strict_types=1 );
// also applies to includes and require statements
error_reporting(-1); // maximum error reporting
ini_set('display_errors', '1');
ini_set('display_html_errors', '1');
// EXAMPLE OF A WARNING
ini_set('display_errors', true);
// YOUR ORIGINAL SCRIPT GOES BELOW
...
...
...