How to make search and replace in content through php

I actually can show content and change content while displaying post. Problem is that I am using RSS importer and after importing I want to make search and replace and correct data imported because I know what is wrong with it.

    <?php
      add_action('pmxi_saved_post', 'post_saved', 10, 1);
      $my_post = array(
          "ID"           => $id,
          "post_content" => "1",
      );
     wp_update_post( $my_post );
    ?>

this is code I am using. Problem is that “post_content” does not change to value 1. Basically this code should change whatever is in post $id to value “1”.

Why is this not working? I cannot figure it out for 2 hours now. All examples I have are based on change content while displaying but that does not change content IN database, only what is shown.

Solutions Collecting From Web of "How to make search and replace in content through php"

From the documentation of WP All Import, the pmxi_saved_post action takes one parameter, $id, which is “the ID of the post/page/Custom Post Type that was just created.”

So, your post_saved() callback should look like this:

add_action('pmxi_saved_post', 'wpse246838_post_saved', 10, 1);
function wpse246838_post_saved( $id ) {
    $my_post = array(
            "ID"           => $id,
            "post_content" => "1",
    );
    wp_update_post( $my_post );
}