Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

returning json file content

General discussions related to php

Moderators: macek, egami, gesf

returning json file content

Postby henriquecarv » Sat Apr 26, 2014 1:50 pm

I'm trying to create this Web Search Page where the user will type the keyword in the text field available. using a (method = 'get') the result will be displayed in the same page getting the content from a json file.

I wrote this json file by myself just for testing the page. Until now I just got errors in the result. Does someone knows what to do?

Code: Select all
<!doctype html>
<html>
   <head>
      <title>Web Search Project</title>
   </head>
   <body>
      <center>
         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method = 'get'>
         <h1>Search Engine</h1>
            <input type='text' name='k' size='100'/>
            <input type='submit' value='Search'/>
         </form>
         <hr />
         <?php

            $jsonDecode=json_decode(file_get_contents(file_get_contents("E:\\Desktop\\test.json")),true);
            $result = array();

            foreach($jsonDecode as $person)   
            {
               $result[]=$person{'Person'};
            }
         ?>
      </center>
   </body>
</html>


json file:

Code: Select all
{
    "id1": {
        "description":"blah blah"
      "href":"http://www.google.com",
        "keywords":"Search, News",
    },
    "id2": {
        "description":"more blah"
      "href":"http://www.nytimes.com",
        "keywords":"News",
    }
}
henriquecarv
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Apr 26, 2014 1:37 pm

Re: returning json file content

Postby seandisanti » Tue Apr 29, 2014 10:25 pm

you should look at using jquery and AJAX to do calls behind the scenes. Here's a quick example and explanation from w3schools: http://www.w3schools.com/jquery/jquery_ ... t_post.asp
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron