Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4231676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T01:59:56+00:00 2026-05-21T01:59:56+00:00

I am making a script that gets the content and images of blog posts

  • 0

I am making a script that gets the content and images of blog posts using DOM and regular expressions.

The script is finished except the following. My aim is to get the content (it is done) all the post’s images EXCEPT THE FIRST and add them to the new content with value varcontent1, 2, 3 and so on.

The script runs 25 times (the number of posts in page), and there is a variable $i. The following code gets the current post content and saves it to $varcontent1. Also it gets all the images of the whole site (with a list of bad words) and prints them as an array.

My question is how can I save the current images to the current post? Finally I will transform them to <img src="xxxx"> (I think I know how to do it).

UPDATED: the results will be submitted to a form. What if I put the current images URLs to a new post variable?

Note: I can get the images with DOM because I load the page, not loadHTML.

preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui', $content, $matches);

    preg_match_all('/\S+(list|of|bad|words)\S+/i', $content, $bads);

    $filtered = array_values(array_diff($matches[0], $bads[0]));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T01:59:56+00:00Added an answer on May 21, 2026 at 1:59 am

    Try using offset…

    preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui', $content, $matches, NULL, 1);
    

    Don’t use 1,2,3… use arrays…

    $varcontent[$i]["content"] = $content;
    $varcontent[$i]["images"] = array_unique($filtered);
    

    When reading posts…

    foreach($varcontent as $content){
        echo $content["content"]; // HTML or plain text
        foreach($content["images"] as $image){
             echo '<img alt="" src="'.$image.'"/>'; // All images
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP page that gets its content by making an HTTP request
I'm making a php script that stores 3 arrays: $images , $urls , $titles
I'm having some trouble removing an element that gets added dynamically to the DOM.
i have a script that calls a php file and gets an JSON object
Hey, I've just started learning JavaScript and I'm making a little script that generates
In the following list.java i am making a URL near the bottom that grabs
So I am making a program that has a script Set of Steps to
So I have a script that gets passed a URL as a get param,
Using VBA. My script moves a file into a directory. If that filename already
I am making a cross domain request using script tag hack and jsonp. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.