Jump to content

Need guidance seperating all this stuff.


Tjazi

Recommended Posts

Ok, so I have a massive file of information, now FIND AND REPLACE techniques do not work, so making a PHP script, should. Now I have the information like so (exactly how it is in the file)

 

id<br>
name<br>
title<br>
album<br>
year<br>
id<br>
name<br>
title<br>
album<br>
year<br>
id<br>
name<br>
title<br>
album<br>
year<br>

So on and so forth for about 4,500 times. (Obviously the values are set in the text file though). Now I am wondering how will I go about putting it into my database? I know how to insert:

mysql_query("INSERT INTO listings VALUES('','','','','')");

But not sure how to make my text file do it in the format it is in.

 

I need to find a solution by tommorow morning at the latest, any ideas please?? :D

 

Note 1: The <br> tags are in the file.

Note 2: The insert command will insert the information from every 5 lines.

Link to comment
https://forums.phpfreaks.com/topic/79559-need-guidance-seperating-all-this-stuff/
Share on other sites

You can easily modify this to fit what you need.

 

<?php

$string ="id<br>
name<br>
title<br>
album<br>
year<br>
id<br>
name<br>
title<br>
album<br>
year<br>
id<br>
name<br>
title<br>
album<br>
year<br>";

$string = explode("<br>", $string);

$x=1;

foreach($string AS $alone){
echo $alone . " ";

	if($x == '5'){
		echo "<br>\n";
		$x=0;
	}
$x++;
}
?>

 

Of course, if it's a file. Just change the $string variable to

 

$string = file_get_contents('file.txt');

 

My results were:

 

id name title album year 
id name title album year 
id name title album year 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.