warby12 Posted July 1, 2008 Share Posted July 1, 2008 Hi, I've written this function below to open a html file, read the file contents into a string, replace some stuff in the string and write it out again. But it is creating havoc, adding characters from the middle to the end and deleting stuff seemingly at random. I'm thinking it is possibly something to do with the way I am handling the file or a character encoding problem or an OS problem. Any help would be greatly appreciated. // change text $page_text = file_get_contents($file, filesize($file)); $temp_text = $div . "<H2><div name=\"item_date\">" . $date . "</div></H2>" . "<p><span class=\"text_style_1\"><div name=\"item_title\">" . $title . "</div></span>" . "<div name=\"item_body\"><span class=\"text_style_cms\">" . $item . "</span></div>" . "<div name=\"item_link\"><span class=\"text_style_cms\"><A href=\"" . $url . "\">" . $url . "</A></span></div>" . "<div name=\"item_email\"><span class=\"text_style_cms\">" . $email . "</span></div>" ; $page_text = str_replace ($div, $temp_text, $page_text); // write file $handle = fopen($file, 'w+b'); $bytes_chnged = fwrite($handle, $page_text); $changed = fclose($handle); ??? Link to comment https://forums.phpfreaks.com/topic/112710-file-reading-and-writing-problem/ Share on other sites More sharing options...
phpSensei Posted July 1, 2008 Share Posted July 1, 2008 try <?php $temp_text = <<<HTML <b> Insert HTML here </b> HTML; // insert data ?> Link to comment https://forums.phpfreaks.com/topic/112710-file-reading-and-writing-problem/#findComment-578815 Share on other sites More sharing options...
warby12 Posted July 1, 2008 Author Share Posted July 1, 2008 Hi phpSensei, Thanks That has created a whole nother world of weirdness but I will follow it through to see what's happening. Thanks for the pointer. I never thought file writing could be so fiddly, must be my lack of knowledge. Link to comment https://forums.phpfreaks.com/topic/112710-file-reading-and-writing-problem/#findComment-578828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.