|
Posted by Steve on 10/06/06 20:11
| $quotestxt = "$DOCUMENT_ROOT/quotes.txt";
| $quotes_file = fopen($quotestxt, 'r+');
| while (fread($quotes_file, 1024)) {
| $pattern = '^[\"]';
| $quote_roster = preg_match($pattern, $quotes_file);
| print_r($quote_roster);
| }
also, $pattern never changes based on the conditions in your while
loop...why slow php down by making it reassign a value (the same value) to
$pattern on every iteration? or, for that matter, assign the preg_match
result to a variable in order to call the variable when printing? also,
based on several factors above, you have programmed a glitch. if you get
half of the information in an iteration, say the character that is in your
pattern, but not the rest of the data in the same iteration, then you will
be prone to missing some or all of the data you intend to print. why not try
using this php 4 > function:
$lookFor = '^[\"]';
$records = file_get_contents($DOCUMENT_ROOT . '/quotes.txt');
$records = explode("\n", $records);
foreach ($records as $record)
{
print_r(preg_match($lookFor, $record));
}
if you're using print_r from php 5, then include the second argument set to
true so you don't have to muck with crappy output. or do this for php < 5:
print '<pre style="font-weight;7.25pt; text-align:left;">';
flush();
print_r(blah, blah, blah);
print '</pre>';
flush();
anyway, hth.
btw, i know it is more efficient to do:
$DOCUMENT_ROOT . '/quotes.txt'
rather than "DOCUMENT_ROOT/quotes.txt"...but i wonder if anyone has ever
quantified the savings?
Navigation:
[Reply to this message]
|