Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 02-03-2003, 06:25 AM   #1
Member (9 bit)
 
Join Date: Jan 2002
Location: UK
Posts: 389
PHP Questions

Hi

Well this is what im using to open a test file:

$fp = @fopen("data.dat", "rb") or die("Couldn't open file");

while(!feof($fp))
{
$data .= fgets($fp, 1024);
}
fclose($fp);
$values = explode("\r\n", $data);


Which in other words is taking each line of the data.dat file and assigning:
$values[0] with the first line
$values[1] with the seccond line
$values[2] with the third line

and so on for each line in the file,

this is all working peechy but say i want to output the seccond line, i would use

print (" $values[1] ");

which works fine but i want to only output the first 25 words on that line,
is there a way to do this

Hope someone can help,
and hope i've made some sense : )

James
Battery Powered is offline   Reply With Quote
Old 02-03-2003, 03:48 PM   #2
Member (13 bit)
 
DrZaius's Avatar
 
Join Date: Jul 2000
Location: Fullerton, CA
Posts: 7,030
Hi James,

Use the string tokenizer function to break the big string up into individual words, then use a loop to display on the first 25. Hope that helps.
DrZaius is offline   Reply With Quote
Old 02-05-2003, 06:49 AM   #3
Member (9 bit)
 
Join Date: Jan 2002
Location: UK
Posts: 389
ive been working on a better way still

PHP Code:
function cut_string($thestring) {
    GLOBAL 
$length;
    
$thestring substr($thestring0$length);
    return 
$thestring;
}
$shortened cut_string($values[0]);

print (
" $shortened "); 
works like a charm : )
Battery Powered is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:29 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2