Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need Help With Making A New Array
Old 04-04-2009, 12:57 PM Need Help With Making A New Array
Average Talker

Posts: 26
Trades: 0
firstly, I want to break down for example, a text file, so it reads word by word in to an array. I then want to add this array to an sql database.

I am using explode to use this so this makes the arrray, but when I insert it to the database it comes out just as 'array array array' and not the contents of the file.

if i echo the explode array it comes out with the contents in the browser.

Is there a way to put the results from the explode into a new array that can be inserted into the database.

this is my code

function opening($file)
{
$pattern = "(\.txt$)| (\.php$)";
if(eregi($pattern, $file)){
$file_handle=fopen($file, "rb");
while (!feof($file_handle)){

$line_of_text = fgets($file_handle);
$parts = explode(" ", $line_of_text);
printing($parts);




}
fclose($file_handle);}
else {
echo "Cant open that file type <p>"; }

}





function newarray($parts){


$data = array();
for($i = 0; $i < count($parts); ++$i)
$data[] = $parts;


}

I am trying to make a function to put this wanted data into a new array, but not sure how. obviously need a loop

Any help would be great. cheers
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-04-2009, 01:28 PM Re: Need Help With Making A New Array
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try:
PHP Code:
$data file_get_contents($file);
$words explode(' ' $data);

foreach(
$words as $word)
{
     
$sql "INSERT INTO table VALUES($word);";
     
mysql_query($sql);

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-04-2009, 01:46 PM Re: Need Help With Making A New Array
Average Talker

Posts: 26
Trades: 0
ah thank you so much!, much simpler to what i was thinking i had to do.
applebiz89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need Help With Making A New Array
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.10298 seconds with 12 queries