Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How do i open a file, find something in that file, and replace it?

Featured Replies

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?

  • 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 :p

 

$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);

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 :p

 

:o And yet again, you ask us to get naked with you!!

 

Something you wanna tell us bocaJ?

  • Author
Something you wanna tell us bocaJ?

 

Whatever you wanna know ;)

 

But hey, what can i say, am a swinger (jokes!) :pp

 

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? :(

Whatever you wanna know ;)

 

But hey, what can i say, am a swinger (jokes!) :pp

 

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 :rofl:

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.

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.