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
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 

Link to comment
Share on other sites

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.