How to get specific rows in a txt file in PHP?

Here is my problem, I am trying to make a script that create a new table in a database for each new txt file I get. This part is ok but then I want to get some specific rows or words in the txt file to update the table.

Here is my code :


    $servername = "localhost"; 
    $username = "root";        
    $password = "";            
    $dbname = "exctraction";         

    $conn = new mysqli($servername, $username, $password, $dbname); 

    if ($conn->connect_error)
        die("Connection failed: " . $conn->connect_error);    

    foreach (glob("*.txt") as $filename) 

        $sql = "CREATE TABLE IF NOT EXISTS `$filename` (
               `id` int(100) unsigned NOT NULL AUTO_INCREMENT,         
               `device` varchar(30) NOT NULL,
               `label` varchar(30) NOT NULL,
                           `configured` varchar(3) NOT NULL,
               PRIMARY KEY (`id`)
            )  ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;"; 

        if ($conn->query($sql) === TRUE) 
            echo "<b>La table ".$filename."&nbsp;"." a &eacute;t&eacute; cr&eacute;&eacute;e avec succ&egrave;s.</b> </br>"; 
            echo "<u>Erreur lors de la cr&eacute;ation de la table :</u> </br>" . $conn->error; 

                $file  = fopen( $filename, "r" );
                $content = "";

                for( $i = 0 ; $i < 158 ; $i++)  

                    $content .= fgets($file, 200);
                        $content_array = file($filename);
                        print_r ($content."</br>");


I want to display the lines I need and then make an UPDATE TABLE with these lines.

The lines I want to get are from 57 to 65 in the txt file, but I am not able to get these only lines.

Source: sql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.