This is a discussion on JSON within the PHP Language forums, part of the PHP Programming Forums category; Hi, I have a file that returns JSON data: <?php $q = strtolower($_GET["q"]); if (!$q) return; $...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I have a file that returns JSON data: <?php $q = strtolower($_GET["q"]); if (!$q) return; $items = array( "Peter Pan"=>"peter@pan.de", "Molly"=>"molly@yahoo.com", "Forneria Marconi"=>"live@japan.jp", "Master Sync"=>"205bw@samsung.com", "Dr. Tech de Log"=>"g15@logitech.com", "Don Corleone"=>"don@vegas.com", "Mc Chick"=>"info@donalds.org", "Donnie Darko"=>"dd@timeshift.info", "Quake The Net"=>"webmaster@quakenet.org", "Dr. Write"=>"write@writable.com" ); echo "["; foreach ($items as $key=>$value) { if (strpos(strtolower($key), $q) !== false) { echo "{ name: \"$key\", to: \"$value\" }, "; } } echo "]"; I want to create a test file that returns the following JSON: [{"TagID":"017b253e-596b-4328-85f5- fd97a783759c","Name":"Física","FileTags":[],"ProfessorTags":[]}, {"TagID":"3fae2160-55f6-4dd0-b856- fd27f5d307e2","Name":"Matemática","FileTags":[],"ProfessorTags":[]}, {"TagID":"883b197e-0cb3-4528-8403-0877d742bf47","Name":"Matemática B","FileTags":[],"ProfessorTags":[]},{"TagID":"f183cb9d-9d92-4c61-b03a- e51cc1205b2b","Name":"Português","FileTags":[],"ProfessorTags":[]}] I am not familiar with PHP and I need to create this to test something. Thanks, Miguel |
|
|||
|
shapper wrote:
> Hi, > > I have a file that returns JSON data: > <cut> > echo "["; > foreach ($items as $key=>$value) { > if (strpos(strtolower($key), $q) !== false) { > echo "{ name: \"$key\", to: \"$value\" }, "; > } > } > echo "]"; > > I want to create a test file that returns the following JSON: Look for json_encode and json_decode functions |
![]() |
| Thread Tools | |
| Display Modes | |
|
|