Viewed   72 times

I am new to PHP. I am implementing a script and I am puzzled by the following:

$local_rate_filename = $_SERVER['DOCUMENT_ROOT']."/ghjr324l.txt";
$local_rates_file_exists = file_exists($local_rate_filename);

echo $local_rates_file_exists."<br>";

This piece of code displays an empty string, rather than 0 or 1 (or true or false). Why? Documentation seems to indicate that a boolean value is always 0 or 1. What is the logic behind this?



Be careful when you convert back and forth with boolean, the manual says:

A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.

So you need to do a:

echo (int)$local_rates_file_exists."<br>";
Tuesday, November 8, 2022

<? and <?= are called short open tags, and are not always enabled (see the short_open_tag directive) with PHP 5.3 or below (but since PHP 5.4.0, <?= is always available).

Actually, in the php.ini-production file provided with PHP 5.3.0, they are disabled by default:

$ grep 'short_open' php.ini-production
; short_open_tag
short_open_tag = Off

So, using them in an application you want to distribute might not be a good idea: your application will not work if they are not enabled.

<?php, on the other side, cannot be disabled -- so, it's safest to use this one, even if it is longer to write.

Except the fact that short open tags are not necessarily enabled, I don't think there is much of a difference.

Friday, November 4, 2022

On user.php page you need to do :-

function init() {
        $arr = array(
                "region" => "valore",
                "price" => "valore2"
                "region" => "valore",
                "price" => "valore2"
                "region" => "valore",
                "price" => "valore2"

        echo  json_encode($arr);
Tuesday, October 4, 2022

You are not appending the variable to the string properly. Also you have to enclose nextpage.php?file=variable within quotes. But you are closing it before the variable name.

<a href="nextpage.php?file=".'$myvar'.>

So try with

echo('<tr> <td> <a href="nextpage.php?file='.$myvar.'"> download now </a> </td> </tr>');
Tuesday, August 2, 2022
<?php if (isset($g1) && $g1!='') { ?>
<a href="img/g1.png"  class="lightbox"  rel="tooltip" data-original-title="<?php print $g1; ?>" data-plugin-options='{"type":"image"}'>
<img class="img-responsive img-rounded wbdr4" src="img/g1.png">
<?php } ?>
Tuesday, September 27, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :