Php write json

hii Good Morning FRIENDS :slight_smile:
Can anyone tell how to write PHP FILE To JSON
Give the Example plzzzzzz tell me how to write

$json = json_encode(array('PHP File'));
file_put_contents('file.json',$json);
4 Likes

Can u tell how to write from PHP to JSON

        <form name="import" method="post" enctype="multipart/form-data">
            <input type="file" name="file" /><br />
            <input type="submit" name="submit" value="Submit" />
        </form>
        <?php
        include ("Database.php");

//if (isset($_POST[“submitbtn”]== “Submit”))
if (isset($_POST[“submit”])) {
$file = $_FILES[‘file’][‘tmp_name’];
//Count The Total Csv file
$abc = count(file($_FILES[‘file’][‘tmp_name’]));
echo"

";
$handle = fopen($_FILES[‘file’][‘tmp_name’], “r”);
$c = 0;

            while (($filesop = fgetcsv($handle, 1000, ",")) !== false) {
                echo "<tr>";
                $contact = $filesop[0];
                $message = $filesop[1];
                if (preg_match('/(7|8|9)\d{9}/', $contact)) {
                    $sql = mysql_query("INSERT INTO csv (contact, message) VALUES ('$contact','$message')");
                    $c = $c + 1;
                    echo "<td>" . $contact . "</td><td>" . $message . "</td>";
                } else {
                    $er = $abc - $c;
                }
            }
            if ($sql) {
                echo "<br>Total Mobile Numbers is: " . $abc . "<br>";
                echo "Vaild Mobile Numbers: " . $c . "<br>";
                echo "Invaild Mobile Numbers: " . $er . " <br>";

                echo "</table>";
            } else {
                echo "There is some Error.";
            }
            echo "</tr>";
        }
        ?>
    </div>
</body>
ContactMessage

I think you need to post more information on exactly what you need @oddz posted an answer to your first question which writes a file in json-format from PHP. What exactly do you want to do with the file you upload in your example code here?

I’m uploading csv file to the database…
The output must be in JSON,i don’t no how to write a JSON in PHP file…
Plz tell meeeeee :frowning:

I’m confused - do you want to change the output (the echo to the screen) or the information you store in the database in json format?

In any case, not something I’ve done - does this page help? : http://php.net/manual/en/function.json-encode.php

There’d be little point in converting to JSON if the data is to go in the database as you’d simply have to extract the data again in order to store it in the database.

ya output should be JSON format, i don’t much about JSON :frowning:
help meeeeeee plssss

@shammu - can you stop with the plzs and mees? We are trying to help you and the constant begging is, at least for me, annoying.

You’re going to have to explain your problem better, in order to get a solution, whether that be from us or even for yourself. So, do take your time and explain what it is you want to accomplish and write it clearly, so we can understand it too.

Scott

1 Like

So again, by “output”, exactly what do you mean? Exactly what do you want to json_encode and where will it be going? As it’s a JavaScript encoding, does that mean that you intend to pass the data back to some other code?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.