Adding stuff from each line? (Fairly urgent)
Posted: Sat Dec 01, 2007 3:33 am
(I've posted this already over on PHPFreaks)
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)
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:But not sure how to make my text file do it in the format it is in.
I need to find a solution by midday today at the latest, any ideas please??
Note 1: The <br> tags are in the file.
Note 2: The insert command will insert the information from every 5 lines.
---
I got a reply of:
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)
Code: Select all
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>Code: Select all
mysql_query("INSERT INTO listings VALUES('','','','','')");I need to find a solution by midday today at the latest, any ideas please??
Note 1: The <br> tags are in the file.
Note 2: The insert command will insert the information from every 5 lines.
---
I got a reply of:
And I replied...You can easily modify this to fit what you need.
Of course, if it's a file. Just change the $string variable toCode: Select all
<?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++; } ?>
My results were:Code: Select all
$string = file_get_contents('file.txt');
Code: Select all
id name title album year id name title album year id name title album year
But nothing since then, anyone got anymore help please?? Thank you.But how would I get them into a mysql_query command? I've tried $string[0] and $alone[0]but none have worked.