Read Specific Line from txt file and insert in database using php
create database table google
| text |
| text |
create index.php
<?php
$connection = new mysqli("db hostname", "db username", "db password", "db name");
// Check connection
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
$sql = mysqli_fetch_assoc(mysqli_query($connection,"SELECT * from `google` order by id desc limit 1"));
$count = $sql["id"];
$myFile = "0google.txt";
$lines = file($myFile);//file in to an array
echo $lines[$count]; //line 2
$lines = $lines[$count];
//$lines = preg_replace('/[^A-Za-z0-9. -]/', '', $lines[$count]);
$snug = str_replace(' ','-',$lines);
$sql = mysqli_query($connection,"INSERT INTO `google`(`category`,`category-snug`) VALUES ('$lines','$snug')");
?>
<== index.php end==>
<== google.txt start ==>
3D printing service
Aadhaar center
Abarth dealer
Abbey
Aboriginal and Torres Strait Islander organisation
Aboriginal art gallery
Abortion clinic
Abrasives supplier
Abundant Life church
Academic department
A�a� shop
Acaraje restaurant
Accountant
Accounting firm
Accounting school
Accounting software company
Acoustical consultant
Acrobatic diving pool
Acrylic store
Acupuncture clinic
Acupuncture school
Acupuncturist
Acura dealer
Adaptive sports center
Addiction treatment center
Administrative attorney
Adoption agency
Adult day care center
Adult DVD store
Adult education school
Adult entertainment club
Adult entertainment store
Adult foster care service
Adventure sports
Adventure sports center
Advertising agency
Aerated drinks supplier
Aerial photographer
Aerial sports center
Aero dance class
Aerobics instructor
Aeroclub
Aeromodel shop
Aeronautical engineer
Aerospace company
Afghan restaurant
African goods store
African restaurant
After school program
Aged care
<== google.txt end ==>