Stripping the_content() from images then displaying them seperately

Ok, I’ve got content with images removed using this code:

$content = strip_tags(get_the_content(), '<p><a><h2><blockquote><code><ul><li><i><em><strong>');
$content = preg_replace("/[caption.*[/caption]/", '', $content);
$content = str_replace("[/caption]", '', $content);
echo $content;

Now I want to show the images at the end. I’m trying to use this:

Read More
$images = strip_tags(get_the_content(), '<img>');
echo $images;

But it’s not working. Any ideas?

Related posts

Leave a Reply

1 comment

  1. maybe use this regex:

    $pattern = "/<a(.*?)href=('|")([^>]*)('|")(.*?)><img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)class=('|")([^>]*)('|")(.*?)/></a>/i";
    
    
    
    function example_replace ($content) {
       global $post;
    
       $pattern = "/<a(.*?)href=('|")([^>]*)('|")(.*?)><img(.*?)src=('|")([^>]*).(bmp|gif|jpeg|jpg|png)('|")(.*?)class=('|")([^>]*)('|")(.*?)/></a>/i";
       $replacement = '<a$1href=$2$3$4$5><img$6src=$7$8.$9$10$11class=$12$13 <strong>imagelink</strong>$14$15$16/></a>';
       $content = preg_replace($pattern, $replacement, $content);
    
       return $content;
    }