info('Entry ID: ' . $entry->id); if (str_contains($entry->content, $stringToFind)) { $this->info(' - Found occurrence in entry ID: ' . $entry->id); // Extract all image srcs that match the pattern preg_match_all('/src=\"http:\/\/127.0.0.1:8000\/storage([^\"]*)/', $entry->content, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $i => $foundUrl) { $this->info(' - Found image src: ' . $foundUrl); // Compute the replacement for this specific image $relativePath = $matches[1][$i] ?? ''; $newUrl = 'src="https://your-s3-bucket-here/yours-site-static-media-dir-here' . $relativePath; $this->info(' - Will replace with: ' . $newUrl); } } $updatedContent = \str_replace($stringToFind, $stringToReplace, $entry->content); // uncomment the following when your sure about the changes // $entry->content = $updatedContent; // $entry->save(); // $this->info(' - Updated entry ID: ' . $entry->id); } } } }