⊗ppSpJnDS 18 of 83 menu

Sending Data in JSON Format in PHP

When a website is running, it often happens that some URLs return not HTML code, but JSON. Let's write an example of such a page:

<?php $data = [1, 2, 3]; $json = json_encode($data); echo $json; ?>

A more correct approach would be to send the appropriate HTTP header as well:

<?php $data = [1, 2, 3]; $json = json_encode($data); header('Content-Type: application/json'); echo $json; ?>

When accessing a certain file, create an array with numbers from 1 to 100 and output it in JSON format.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline