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

  • Home
  • SEARCH
  • 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 6808893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:44+00:00 2026-05-26T20:00:44+00:00

I have this piece of HTML: <div class=embed> <iframe width=300 height=200 frameborder=0 allowfullscreen= src=http://www.youtube.com/embed/123456></iframe>

  • 0

I have this piece of HTML:

<div class="embed">
<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456"></iframe>
Some text I don't want
</div>

This is how it is being inserted into the HTML:

<div class="embed"><?php echo $item['embed_html']; ?></div>

This is what

 $item['embed_html']

is echoing out:

<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456"></iframe>Some text I don't want

So I don’t want to parse the whole document, just this specific string.

Don’t worry, this isn’t “outside user” inputted HTML, before anyone points out the security issues with allowing raw code on to a page…

I need to extract the HTML but leave the text (so it would look like this):

<div class="embed">
<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456"></iframe>
</div>

There are multiple different embed codes, so I guess what I’m asking is what is the best way to remove text that is not wrapped in an HTML element (between < and >) (<img, <p, <div, <iframe, <object, <embed, <video etc may all be used in this section). Just that if there is any text added to it that is not wrapped in a tag it should remove it from the string.

I don’t want to wrap the offending text in a tag, I want to completely remove it. In a way, the reverse of strip_tags()

  • 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-26T20:00:44+00:00Added an answer on May 26, 2026 at 8:00 pm

    This is a simple regex that would do what you want in 99% of cases:

    <[^>]+>
    

    All it does though is match XML/HTML tags. That’s it. There’s no clean way of telling it to only match text inside the DOM-subtree of a certain node (such as <div class="embed">). For this you would to use a context free parser, such as a DOM-parser.

    Your sample input would be matched into:

    {
        "<div class="embed">",
        "<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456">",
        "</iframe>",
        "</div>"
    }
    

    Given this: <!-- <foo> --> input text however you would end up with <foo> being extracted despite being technically commented out. Removing all occurences of regex <!--.*?--> beforehand should solve that though.

    Anyway, in general you’re best off using a DOM parser for anything XML/HTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of HTML <div id=fileTreeInviati> <ul class=php-file-tree> <li class=pft-directory> <a href=#
I have a the following html piece : <div onClick=javascript:getComments(this); store-id=143568 class=CountryRow style=padding: 4px;><div
I have this piece of HTML code. <div class=tagWrapper> <i style=background-image: url(https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/390945_10150419199065735_543370734_8636909_2105028019_a.jpg);></i> </div> I
I have this piece of code: <li class=selected><a href=/AmIACandidate.html>Am I a Candidate?</a></li> I need
I have this piece of html in my page. <p><a href=# id=addQueryPart >Add</a></p> <div
I have this piece of html in my page. <p><a href=# id=addQueryPart >Add</a></p> <div
I have the following piece of HTML code: <div class=myclass id =class1> <ol class=list>
Having this piece of HTML: <div id=modal> <select class=country> <option value=></option> <option value=opt>Opt</option> </select>
I have this piece of code in a .cshtml. @using (Html.BeginRouteForm(CheckoutShippingAddress, FormMethod.Post)) { <div
I have this piece of code in my .js.erb file: $(#register_holder).html(<%= escape_javascript(render(layouts/register)) %>); I

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.