February 27, 200917 yr How do i open a file, find something in that file, and replace it? I tried str_replace($old, $new, $data) data is the file i want to replace in and it's correct. i'm using fread to read the file. $old and $new are outputting correctly, if i change them to words, the str_replace works fine?
February 27, 200917 yr Author nope, shouldn't need them, i tried putting them in but it didn't make a difference. This is what i have so far, i'm still learning so bare with me, and any alterations explain rather than just putting them in there $new = $_POST['update_value']; $old = $_POST['original_html']; $myfile = "index.html"; $fh = fopen($myfile, 'r') or die('can\'t open file'); $data = fread($fh, filesize($myfile)); $output = str_replace($old, $new, $data); // $output .= $old; // $output .= $new; // $output .= $data; $fht = fopen($myfile, 'w') or die('can\'t open file'); fwrite($fht, $output); fclose($fht);
February 27, 200917 yr This is what i have so far, i'm still learning so bare with me, and any alterations explain rather than just putting them in there And yet again, you ask us to get naked with you!! Something you wanna tell us bocaJ?
February 27, 200917 yr Author Something you wanna tell us bocaJ? Whatever you wanna know But hey, what can i say, am a swinger (jokes!) I know i'm TERRIBLE with literacy, and you've already pointed out the bear thing with me, i have taken note and i do get it right sometimes, but sometimes i just forget to pay attention to what i'm writing. Bad habbits an' all. I'm sorry, forgive me?
February 28, 200917 yr Whatever you wanna know But hey, what can i say, am a swinger (jokes!) I know i'm TERRIBLE with literacy, and you've already pointed out the bear thing with me, i have taken note and i do get it right sometimes, but sometimes i just forget to pay attention to what i'm writing. Bad habbits an' all. I'm sorry, forgive me? ROFL
February 28, 200917 yr Have you considered file_get_contents()? $out = file_get_contents("file_to_search.html"); $out = str_replace($old, $new, $out); echo $out; then if you want to save, just fwrite() $out.
February 28, 200917 yr Author i tried, it didn't work. It just truncated the page and wrote "array", although that's probably mybad. I didn't have time to fiddle with it more, i'll try again when i get some time.
Create an account or sign in to comment