Jump to content

Resource id #4 -- Help :(


Henaro

Recommended Posts

Hello!~

I have encountered an error and I am in need of help.  Here is there error:

[code]Resource id #4[/code]


Here is the code that is producing it:

[code]<?PHP
$view_post = fopen ('posts.txt', 'rb');
$view_post = str_replace(' [ascii] ', '<pre>', $view_post);
$view_post = str_replace(' [/ascii] ', '</pre>', $view_post);
printf("$view_post");
?>[/code]

I am not sure what Resource id #4 is.  I google'd it and found a lot of stuff about MySQL, but I am not using MySQL.  If anyone could tell me what is wrong with this please do.

Thanks,
Henaro
Link to comment
https://forums.phpfreaks.com/topic/29061-resource-id-4-help/
Share on other sites

You do not want to use the same variable for both the file pointer (the result of the fopen) and a text string. A much better solution would be:
[code]<?php
$fp = fopen ('posts.txt', 'rb');
$view_post=fread($fp,filesize("posts.txt"));
$view_post = str_replace(' [ascii] ', '<pre>', $view_post);
$view_post = str_replace(' [/ascii] ', '</pre>', $view_post);
echo $view_post;
fclose($fp);
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/29061-resource-id-4-help/#findComment-133226
Share on other sites

Archived

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

×
×
  • Create New...

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.