Jump to content

Recommended Posts

Hi Guys - I'm very new to PHP and I have been reading for quite some time but I'm not quite understanding a specific component.

 

Basically what I am trying to achieve is; [Not sure how to put it in english so I'll step through what I am doing initially in list form;]

 

1. I run a script which outputs a generically 6x lines of text (Will always be 6 lines) followed by outputting "a variable" amount of rows which contain data which I would like to store as individual variables which are parsed into an array which I can then use to pull and insert in to a specific MYSQL database.

 

The way that the text file is layed out seems very straight forward; I.E...

15 columns containing data

11 columns containing no data / blank / spacial seperators

Variable amount of rows

Each column has a specific "descriptor" - name of the colum/purpose

 

My current script is below - starting it off; - Using it for self learning purposes

 

<?php

 

//Defines a variable for the results file I'm pulling information from;

 

$myFile = "./'results file here.txt'";

 

// Define a variable and the string that is pulled from line 8 in the results file will be outputted

 

$row1 = file($myFile); //Pulls First Row of the specific file

echo $lines[8]; // Line 8

?>

 

 What I am hoping to do is some how produce a regular expression which will create a variable dynamically depending on the amount of rows that are present and add that content to an array. From here I would like to pull the specific column values from each row and output them in to a new array which I can then use to drop the column and row information in to the MYSQL Database.

 

The main question is - Is this an unorthadox over complicated way of achieving something that potentially could be done using an export/import type function within PHP? The last thing I would like to see is me trying to script an EXPORT function which has already been created for this exact purpose :)

 

Any assistance would be hugely appreciated - sorry if this makes no sense.

 

 

Thanks

 

A

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/280231-not-quite-getting-it-please-help/
Share on other sites

just a thought...

rather than

<?php

 

//Defines a variable for the results file I'm pulling information from;

 

$myFile = "./'results file here.txt'";

 

// Define a variable and the string that is pulled from line 8 in the results file will be outputted

 

$row1 = file($myFile); //Pulls First Row of the specific file

echo $lines[8]; // Line 8

?>



try this

<?php
$myFile = "FILE NAME AND PATH HERE"; /* no need for the single quotes */
$lines = file($myFile) /* this creates an array of all the lines in the file NOT just the first line */
echo $lines[8]; /* this will display the 9th line - Array element begin with zero - $lines[0] */
?>



You will need to use explode to get each separate pice of data in a line
 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.