PhiDAo
PhiDAo

Reputation: 3

How to write Boolen json to Data in PHP

I have json, and i want write boolen of vpn to file.

{
    "ip": "113.169.100.228",
    "security": {
        "vpn": false,
        "proxy": false,
        "tor": false
    },
    "location": {
        "city": "",
        "region": "",
        "country": "Vietnam",
        "continent": "Asia",
        "region_code": "",
        "country_code": "VN",
        "continent_code": "AS",
        "latitude": "16.0020",
        "longitude": "105.9984",
        "time_zone": "Asia/Vientiane",
        "locale_code": "en",
        "metro_code": "",
        "is_in_european_union": false
    },
    "network": {
        "network": "113.160.0.0/11",
        "autonomous_system_number": "AS45899",
        "autonomous_system_organization": "VNPT Corp"
    }
}

How to write "vpn": false to php?

I use , it don't write to to file data.html

<?php

 $status = $details_3->security->vpn;
 
 $fp = @fopen('data.html', "a");


if (!$fp) {
    echo 'error';
}
else
{
    
    fwrite($fp, $status);
    fwrite($fp, "\r\n");
    fclose($fp);
}
 
?>

Please help me, when i echo $status , it can show, but don't write to file

Upvotes: 1

Views: 32

Answers (1)

Barmar
Barmar

Reputation: 780842

When you convert true and false to strings, they become "1" and "". If you want to write something else, you have to do the conversion yourself, e.g.

fwrite($fp, $status ? "true" : "false");

Upvotes: 2

Related Questions