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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:40:53+00:00 2026-05-14T21:40:53+00:00

Hi guys I’m using this wonderful class here to do a bit of code

  • 0

Hi guys I’m using this wonderful class here to do a bit of code embed filtering: http://simplehtmldom.sourceforge.net/. It extends the PHP DOM document class.

Pretty much what I am doing is parsing a string through this class that contains embed code, i grab the unique bits of information eg id, width, height send through a handler function which inserts the id, width, height etc into my predefined “safe” template and reinsert my safe template in the place of the embed code the user has put in. May seem a backward way of doing it but it’s the way it has to be done 🙂

All of that works fine. Problem is when there is more than just embed code contained in the string, as I can’t just replace the embed code i can only replace the entire string which wipes the rest of the tags etc string. For example if there were a p tag that would be wiped.

So my question is how using this class can i just replace the certain part of the string? Spent the last few days trying to work this out and need some more input. It appears the class can do this so i’m stumped.

Here’s a basic version of what i have so far 🙂

    // load the class
    $html = new simple_html_dom();

    // load the entire string containing everything user entered here
    $return = $html->load($string);

    // check for embed tags
    if($html->find('embed') == true
    {
         foreach($html->find('embed') as $element)
         {
              // send it off to the function which returns a new safe embed code
              $element = create_new_embed($parameters);

              // this is where i somehow i need to save the changes and send it back to $return
         }
    }

Any input would be gratefully appreciated. If i have explained my problem well enough please let me know 🙂

  • 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-14T21:40:54+00:00Added an answer on May 14, 2026 at 9:40 pm

    When you do this:

    foreach($html->find('embed') as $element)
    

    You’re creating a simpleHTMLdom element object – its not a simple variable you can just use as an assignment. For exmaple, if the element was:

    <embed>Some Embed Code Here</embed>
    

    You could change it by doing the following:

    $element->innertext = "Hello world";
    # the element is now <embed>Hello world</embed>
    

    of if you want to change the element completely:

    $element->outertext = "<p>Now I'm a paragraph</p>";
    

    and you’ve replaced the embed entirely.

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

Sidebar

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.