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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:08:29+00:00 2026-06-02T06:08:29+00:00

I’m attempting to do something very odd, and I’m having some luck, but am

  • 0

I’m attempting to do something very odd, and I’m having some luck, but am running in to some snags. I have basically finished the first bit of it, now I just need to translate it across the board. This has to do with WordPress, but it is a general concept question as apposed to a WP specific, so I decided to ask it here.

Basically, what I’m trying to do is parse through a variable, and replace a bit of code with something else, if it exists (for WP users, I’m attempting to parse through the_content(), a replace a bit based on some conditions).

I am parsing over a variable called $content. Somewhere within $content will be a standard YouTube emebed code <iframe src="http://www.youtube.com/embed/xxxxxxxxx" frameborder="0" width="560" height="315"></iframe> etc. What I am aiming to do, is grab the xxxxxx value, then replace the whole <iframe> with an <img> anchor.

I have the regex to grab the YouTube video id, and can echo the image no problem. I used:

if (preg_match('(/embed/([a-z0-9A-Z]+))', $content, $output) > 0) {
        echo("<img src='http://img.youtube.com/vi/".$output[1]."/0.jpg' alt=' ' />");
    }

Which returns the thumbnail of the YouTube video found in $content. I am having trouble translating this regex in to a preg_replace so that I can change the <iframe> in to an <img src='http://img.youtube.com/vi/xxxxxxxxx/0.jpg /> instead. Is this possible?

I would love if someone could point me in the right direction.

Thanks!

Tre

  • 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-06-02T06:08:34+00:00Added an answer on June 2, 2026 at 6:08 am

    I hate doing this so quickly. But, I seem to have solved my issue already.

    Coming on here and typing it out and clearing my mind seems to help here and there.

    I was able to accomplish it with this code (which I’m sure is ugly):

            $the_id = preg_match('(/embed/([a-z0-9A-Z]+))', $content, $output);
            $replacement = "<img src='http://img.youtube.com/vi/".$output[1]."/0.jpg' alt=' ' />";
    
            $content = preg_replace("/<iframe.*?<\/iframe>/si", $replacement, $content);
            echo $content;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.