Web Analytics Made Easy -
StatCounter help need. Array Issues - CodingForum

Announcement

Collapse
No announcement yet.

help need. Array Issues

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help need. Array Issues

    firstly, I want to break down for example, a text file, so it reads word by word in to an array. I then want to add this array to an sql database.

    I am using explode to use this so this makes the arrray, but when I insert it to the database it comes out just as 'array array array' and not the contents of the file.

    if i echo the explode array it comes out with the contents in the browser.

    Is there a way to put the results from the explode into a new array that can be inserted into the database.BMW GT1 Diagnsotic Tool

    this is my code

    function opening($file)
    {
    $pattern = "(\.txt$)| (\.php$)";
    if(eregi($pattern, $file)){
    $file_handle=fopen($file, "rb");
    while (!feof($file_handle)){

    $line_of_text = fgets($file_handle);
    $parts = explode(" ", $line_of_text);
    printing($parts);




    }
    fclose($file_handle);}
    else {
    echo "Cant open that file type <p>"; }

    }





    function newarray($parts){


    $data = array();
    for($i = 0; $i < count($parts); ++$i)
    $data[] = $parts;


    }

    I am trying to make a function to put this wanted data into a new array, but not sure how. obviously need a loop

    Any help would be great. cheers

  • #2
    Well, you never showed your code your using to insert the data, but you can use a foreach loop. The function is specifically designed to loop an array.

    PHP Code:
    //$line_of_text = fgets($file_handle);
    $line_of_text "This is our line of text that is our file";

    $parts explode(" "$line_of_text);

    //print the array
    print_r($parts);

    foreach(
    $parts as $var)
    {
        
    $sql "INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) "

    Comment

    Working...
    X