Let’s give it a try:
$str="<img src="http://myserver.mydomain/picture.png" />";
$pattern ='#<img src="http://.*/(.*)" />#';
$replace="<img src="http://http://i0.wp.com/$1?quality=70&strip=all />"";
$result = preg_replace($pattern, $replace, $str);
The $pattern is quite simple and very specific. You might need to generalize it a bit more but it should show you the direction to go. E.g. it takes no care of possible whitespace. A first attempt to take care of this:
$pattern ='#<\s*img\s*src\s*=\s*"http://myserver.mydomain/(.*)"\s*/\s*>#';
Related Posts:
- Removing any and all inline styles from the_content()
- how to display post content without post image?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- How do I display main query posts in random order using add_filter
- How to exclude native lazy loading from first image in post content?
- Rewrite image links from attachment id to attachment link
- Prevent WordPress from putting around specific element
- Add review box by function at top or bottom of content
- Assign custom class to post content images
- the_content() not displaying the full post
- How to get ‘post_content’ without stripping tags?
- removing inline styles from wp-caption div
- Apply the_title() filter in post & page title, but not in menu title
- Update post counts (published, draft, unattached) in admin interface
- How to get Images included in Post
- Find the post an attachment is attached to
- How to disable content pagination?
- Adding a div class or id inside the_content()
- Can I load posts via Ajax?
- Unattaching images from a post
- Exclude category on blog list page
- How to remove_filter that filters iframes in posts? [duplicate]
- Filter posts by author and category simultaneously
- how to grab first link in post… and of course call it
- Load post content into div with ajax
- Add an image box besides featured image?
- How to add custom content (text/image) at start of content (IN content ie the same line)
- If specific user role then sticky post
- Remove inline width from figure
- How to show video from specific category on sidebar?
- the_posts filter been called multiple time
- Remove permalink from images when inserting into post
- Only display posts after current date
- Image Insert into posts and pages not working after 3.2.1 update
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- Copying and pasting emoji in a wordpress post
- Why content_arr[‘extended’] removes paragraph tags?
- pre_get_posts query between 2 dates (date stored in custom post meta)
- how to remove dash (-) post status from post title on posts listing page wordpress
- Get latest posts from WordPress site without header, menu and sidebar
- How to display featured image without it appearing in post?
- Can I use images as anchor tags with
- creating front end image uploader that uploads images as posts
- Errors when uploading images in WP 3.5
- Adding the_date inside tags around the_content
- How to hide html tags on revision comparison pages?
- Ajax post filters not working
- Show the content that is after the excerpt using child theme
- Display Meta Values in Custom Filter – Admin Custom Posts
- More then one menu items are assigned with “current-menu-item” class
- Get attachments for posts that belongs to a specific category
- Get all images in post and comments like Twitter before post title
- Redirect to another page using contact form 7? [closed]
- How to check if single.php has already called the_post_thumbnail function
- Thumbnail Image to go in the post aswell
- How to disable the_excerpt from one post
- Filtering posts on Post Administration Page by Week Number instead of by Month
- Upload attachment from external site
- Get URL from all images in a post
- Change the default blog post post attribute template name from “default template” to something else
- Disable posts generated from image uploads
- Is it possible to add a shortcode below post title?
- Post filtering is returning blank page
- Image behind the post’s title
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Show more than 200 images in one post
- Hide thumbnail if there is a gallery on the post
- Image on rss feed on post
- How to Featured content with images in home page?
- Where to insert the other site image url for our wordpress post
- select post preview image from nextgen gallery
- How to show a featured image inside a post in only 1 single category
- wp_list_categories() Exclude All Categories Except One
- Get current taxonomy and display query accordingly
- Show only posts with titles/permalinks that do not contain certain words
- Filter posts by month (dropdown)
- How to limit wordpress the_excerpt() dynamically
- Display image gallery if more than 1 image
- Center crop the feature image
- How to add a block to a category page?
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- Add id attribute to h1 element of wordpress post
- Add another feature image box
- ‘posts’ table should not store the absolute image path
- How to make an image appear as a thumbnail in the blog post?
- How can I alternate styling of images in a post? [closed]
- Is it possible to completely replace a post with an action/filter?
- Customizing individual images on posts
- Update all images url imported from HTML pages
- How to modify specific parts of a post content in WordPress
- Post thumbnail dependant on category
- Latest news mini images
- How do I insert a custom field in a user submitted post?
- Only show posts with image and the correct ammount of posts in loop
- Extra Theme – Fit image inside of Featured Post Slider
- Stripping tag from elements in post
- Get attachment if matches a variable
- Full width images within post content
- Download button under all images WordPress