Henaro Posted December 1, 2006 Share Posted December 1, 2006 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 More sharing options...
fert Posted December 1, 2006 Share Posted December 1, 2006 [code]$view_post = fopen ('posts.txt', 'rb');$view_post=fread($view_post,filesize("posts.txt"));$view_post = str_replace(' [ascii] ', '<pre>', $view_post);$view_post = str_replace(' [/ascii] ', '</pre>', $view_post);echo $view_post;fclose($view_post);[/code] Link to comment https://forums.phpfreaks.com/topic/29061-resource-id-4-help/#findComment-133154 Share on other sites More sharing options...
Henaro Posted December 1, 2006 Author Share Posted December 1, 2006 Wow thanks for the speedy reply. It works good now. Thanks :D Link to comment https://forums.phpfreaks.com/topic/29061-resource-id-4-help/#findComment-133162 Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.