Avatar of evibesmusic
evibesmusic
Flag for United States of America asked on

How to use PHP to query the contents of a JSON array stored in a flat file and return the result?

Experts,

I have a flat file (users.php) with a JSON array stored within.

The JSON array takes the following format:
[{"name":"Sam Smith","profltitle":", MBA","location":"San Francisco","displayspecialty":"Accounting","headshotphoto":"2235396_photoweb.jpg","homepageurl":"http:\/\/example.com"},{"name":"Paula Jones","profltitle":", MA","location":"San Jose","displayspecialty":"Human Resources","headshotphoto":"2235555_photoweb.jpg","homepageurl":"http:\/\/example.com"}]

Open in new window


Users are allowed to specify a search term via a textbox:
<input name="searchfor" id="searchfor" type="text" />

Open in new window


Using the search term provided by the user I need to query the JSON array and pull results that match the given search term. The matching values need to be returned in a JSON format.

This is the programming logic as I see it now:

<?php
//DEFINE SEARCH TERM AS PROVIDED BY USER
$term = addslashes($_POST['searchfor']);
//DEFINE JSON ARRAY
$json_array = fopen('users.php');
//USING SEARCH TERM QUERY ARRAY
...
//PROVIDE THE RESULTS IN JSON FORMAT
...
?>

Any assistance would be helpful.
PHPJavaScript

Avatar of undefined
Last Comment
evibesmusic

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
gr8gonzo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
evibesmusic

ASKER
@gr8gonzo:

Thank you very much. Works perfectly!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy