Debt Help | Debt Help | Librerias | Loans | Your File Host
PHP Questions [Archive] - PCMech Forums

PDA

View Full Version : PHP Questions


Battery Powered
02-03-2003, 07:25 AM
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

DrZaius
02-03-2003, 04:48 PM
Hi James,

Use the string tokenizer (http://www.php.net/manual/en/function.strtok.php) function to break the big string up into individual words, then use a loop to display on the first 25. Hope that helps.

Battery Powered
02-05-2003, 07:49 AM
ive been working on a better way still


function cut_string($thestring) {
GLOBAL $length;
$thestring = substr($thestring, 0, $length);
return $thestring;
}
$shortened = cut_string($values[0]);

print (" $shortened ");


works like a charm : )