Title: Getting the_content into a PHP variable&#8230;
Last modified: August 19, 2016

---

# Getting the_content into a PHP variable…

 *  Resolved [alexjames01](https://wordpress.org/support/users/alexjames01/)
 * (@alexjames01)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/getting-the_content-into-a-php-variable/)
 * Hey,
 * I’m trying to find a way to get the content of a post into a $variable so i can
   modify the content in the loop (on the fly) using str_replace and then display
   it.
 * The reason for this is that the post content is coming from a rss feed (an image
   service) and the picture displayed on the post is a thumbnail. I need to change
   the URL of the IMG tag so it displays the full picture.
 * The service has different RSS feeds for thumbnails, medium sized images, and 
   full sized images. All images have similar urls except they end in: -Th.jpg (
   thumbnail) -Med.jpg, and -Lg.jpg for large images. So using str_replace in variable
   that holds the content would easily work.
 * I am pulling the thumbnail RSS feed which is also being put into a wordpress 
   post. I need it to PULL the thumbnail feed for the thumbnail image on the front
   page… but when clicked, i would like to have the large image displayed.
 * Only way i can think to do this is editing the content within the template file
   which would mean i need to:
 * – Set the post content as a variable
    – use STR_REPLACE to replace -Th.jpg with-
   Lg.jpg – Display the new content
 * Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [NC@WP](https://wordpress.org/support/users/ncwp/)
 * (@ncwp)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/getting-the_content-into-a-php-variable/#post-834007)
 * Use [output buffering](http://php.net/manual/en/ref.outcontrol.php):
 *     ```
       ob_start();
       the_content();
       $content = ob_get_clean();
       ```
   
 * Now you can run `str_replace()` on `$content`…
 *  Thread Starter [alexjames01](https://wordpress.org/support/users/alexjames01/)
 * (@alexjames01)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/getting-the_content-into-a-php-variable/#post-834017)
 * Thank you so much! Worked wonderfully!
 *  [roblito](https://wordpress.org/support/users/roblito/)
 * (@roblito)
 * [17 years ago](https://wordpress.org/support/topic/getting-the_content-into-a-php-variable/#post-834243)
 * I had struggled to do a string replace on the category name (add an ‘s’) using
   the_category() and this worked for me too. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Getting the_content into a PHP variable…’ is closed to new replies.

## Tags

 * [image](https://wordpress.org/support/topic-tag/image/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [str_replace](https://wordpress.org/support/topic-tag/str_replace/)
 * [the_content](https://wordpress.org/support/topic-tag/the_content/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [roblito](https://wordpress.org/support/users/roblito/)
 * Last activity: [17 years ago](https://wordpress.org/support/topic/getting-the_content-into-a-php-variable/#post-834243)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
