Home>
Name = Hamburg, Classification = Western food, Principal component = Protein
Name = Sushi, Classification = Japanese, Main ingredient = Carbohydrate
Name = Milk, Classification = Drink, Main ingredient = Calcium
$fp = fopen ("test.txt", "r");
while (($data = fgetcsv ($fp, 1024))! == false) {
$tmp =&$datas [];
foreach ($data as $x) {
$y = explode ("=", $x);
$tmp [trim ($y [0])] = trim ($y [1]);
}
}
unset ($tmp);
fclose ($fp);
print json_encode ($datas, JSON_UNESCAPED_UNICODE);
$(function () {
$("# button"). click (function (event) {
$.ajax ({
type: "GET",
url: "test.php",
data: {val: null},
dataType: "text"
}). done (function (data) {
var test = JSON.parse (data);
for (var key in data) {
$("# parse"). append ('key:' + key + ': value:' + data [key] + "<br/>");
}
}). fail (function (XMLHttpRequest, textStatus, errorThrown) {
alert (errorThrown);
});
});
});
From the parsed data
Key: Name Value: Hamburg
Key: Classification Value: Western food
Key: Main component Value: Calcium
I want to do something like A huge number of keys and values are displayed. What should I do?
If i run php alone and display before parse
[{"Name": "hamburger", "classification": "Western food", "main ingredient": "protein"}, {"name": "sushi", "classification": "Japanese food", "main ingredient": "Carbohydrate"}, {"Name": "Milk", "Classification": "Drink", "Main ingredient": "Calcium"}]
This is now
-
Answer # 1
Related articles
- database value range search (php)
- javascript php → javascript pass by value
- [php] if the destination file of the form is hit directly with the url, the value cannot be passed
- php - how to make each looped value copyable to the clipboard (javascript)
- [php] i want to get the value of td in the table generated by foreach
- python 3x - how to extract data that meets the value conditions from another data frame based on the value of one data frame
- i want to get the value of where specified in the query builder in cakephp3
- php - i would like to know how to get each past numerical value with "ahrefs api"
- javascript - i want to extract a value from a variable
- php - i want to specify the value of getmimetype () in the part to do new uploadedfile ()
- php - function execution and return value after routing without framework
- i want to group by a specific value between php associative arrays and aggregate them
- php - the return value of array_multisort becomes 1
- php - i want to check the array and put its value in the database if there are no duplicates
- should i use `filter_var` for php's` $_post` value?
- php - i want to display the value of a custom field as a column in the wordpress custom post list
- php - stumble when passing a value to a template @included in laravel
- (javascript) i want to extract all the elements based on the value of a specific element in the array
- how to extract and edit the rgb value of each pixel in an image (python)
- php - i can't access the value i got using get in laravel from view
Related questions
- javascript : Is it possible to specify multiple clsss of form->error?
- javascript : How to use JS frameworks with a regular php application?
- javascript : create a service for email verification [closed]
- javascript : How to connect a custom registration form to the database?
- javascript : Autocomplete input with selectable search?
- javascript : Refreshing the HTML page
- javascript : Replacing blocks at the touch of a button
- javascript : Best Platform for Site Performance (PageSpeed Insights)
- php : Ajax, Privat24-api: invalid signature error
- javascript : The modal window opens only for one record
You didn't finish it yet ...
test.php is a mechanism that returns json, so dataType should be json
Since the return value data is an array, first turn it normally with for (or forEach)
Use Object.entries to extract combinations from objects
Direct from text