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 7533813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:50:10+00:00 2026-05-30T05:50:10+00:00

I have a rich text field (called description) which containing texts and images I

  • 0

I have a rich text field (called description) which containing texts and images

I try to isolate all the images to modify the src tag to add elements before and after

example : <img src="path/to/myimage.jpg" /> should become <img src="timthumb.php1src=path/to/myimage.jpg&h=50" />

I succeed when there’s just one image in my field, i use this :

            $descriptionencodee = utf8_encode($description);
            $parser = xml_parser_create();
            xml_parse_into_struct($parser, $descriptionencodee, $values);
            foreach ($values as $key => $val) {
            if ($val['tag'] == 'IMG') {
               $first_src = $val['attributes']['SRC'];
               break;
            }           


            $string = $description;
            $replacement = '<img src="'timthumb.php?src='. $first_src .'&h=50" />';
//          $replacement = '${1}<br/>';
            $string = preg_replace("/(\<img\b[^>]*>)/", $remplacement, $string);
            echo $string;

so it doesn’t work when there’s more than one image

  • 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-30T05:50:11+00:00Added an answer on May 30, 2026 at 5:50 am

    This worked for me in a recent project:

    <?php
        $content = $your_html_here;
    
        preg_match_all( '/<img .* \/>/iU', $content, $results );    // Find all <img />
        foreach ( $results[0] as $one_image ){ // Loop through results
            // Replace <img /> with altered <img />
            $content = str_replace( $one_image, str_replace( 'src="', 'src="timthumb.php?h=50&src=', $one_image ), $content );
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table with a field containing RTF (Rich text Format). I
I have a service which takes the user supplied rich text (can have HTML
I have a Django model with a text field. I'm using a rich text
I have notes document with rich text field. In this RTF there is attachment
I have inserted xml into SQL Server 2005 through rich text field successfully, now
I have rich-text file with a few images and text. In my Cocoa app
I have a rich text box which is enabled to CTRL + > (or
is it possible in Wordpress to have the category description use a rich text
I have a string that gets saved as rich text to a SQL field,
I have content in a Rich Text Field where the HTML view of the

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.