Quantcast
Channel: Creating a function that reads a text file from a data-feed and turning it into an object file for php - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Creating a function that reads a text file from a data-feed and turning it into an object file for php

$
0
0

I am creating a store website, but the datafeed I receive is a format separated by bars instead of commas. I want to be able to read from the text file to display the content into a web page and allow the client to search through the merchandise.

Example row:

710734240|8mm - Men's Freemason Ring / Masonic Ring - Gold and Black Inlay Tungsten Ring Comfort Fit|73628|

I tried the looping over the separated items and putting each of them into their own array.

        const my_data = 'test_data.txt';        async function getData() {            const response = await fetch(my_data);            const data = await response.text();            //console.log(data);            const rows = data.split('\n').splice(1);            rows.forEach(elt => {                const row = elt.split('|');                row.forEach(item => {                    const items = item.split(',');                    //    const filtered = items.filter(function (el){                    //    return el != "";                     const lens = items.length;                    //document.getElementById('data').innerHTML = rows +"<br>";                    var goods = {                        ProductId: row[0],                        Name: row[1],                        MechantId: row[2],                        Mechant: row[3],                        link: row[4],                        thumbnail: row[5],                        bigImage: row[6],                        Price: row[7],                        RetailPrice: row[8],                        mainCat: row[9],                        subCat: row[10],                        Description: row[11],                    };                    document.getElementById('data').innerHTML = goods.Description +"<br>";                });                console.log(row);                //console.log(lens);            });        }        getData();

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images