Jump to content

Archived

This topic is now archived and is closed to further replies.

Pipes

HELP PLS! Newbie: fopen() error?

Recommended Posts

Hello: I'm a complete novice trying to split a file of quotations into quotes and authors (it's a .txt file). I've written this short simple script but i'm getting an error message.

[code]$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);
}
[/code]
Th error message is telling me: Parse error: parse error, unexpected T_VARIABLE in C:\XXXX\separate_quotes_from_authors.php on line 15

can anyone tell me what I should looking for? i've tried the manual, but I can't seem to help myself. It's driving me mad!

any help appreciated!
Pipes

Share this post


Link to post
Share on other sites
Which is line 15?

Also, you want to use double quotes instead of single quotes on this line:
[code]<?php $quotestxt = '$DOCUMENT_ROOT/quotes.txt'; ?>[/code]

Ken

Share this post


Link to post
Share on other sites
Thanks Ken: sorry should have mentioned line 15 is the one that begins
$quotestxt = '$DOCUMENT_ROOT/quotes.txt';

I have now changed this to double quotes, but the problem persists.

The location and path is correct (I created a short variable name for the server path above this code.) so I don't know what variable problems to be looking for??

Thanks for trying to help.

best, Andy

Share this post


Link to post
Share on other sites
Use the full url of the document_root

example

$quotestxt = "folder_name/quotes.txt";

[code]
<?php
$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);
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.