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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:39:20+00:00 2026-05-20T01:39:20+00:00

I am reading in html from a few different sources which I have to

  • 0

I am reading in html from a few different sources which I have to manipulate. As part of this I have a number of preg_replace() calls where I have to replace some of the information within the html received.

On 90% of the sites I have to do this on, everything works fine, the remaining 10% are returning NULL on each of the preg_replace() calls.

I’ve tried increasing the pcre.backtrack_limit and pcre.recursion_limit based on other articles I’ve found which appear to have the same problem, but this has been to no avail.

I have output preg_last_error() which is returning ‘4’ for which the PHP documentation isn’t proving very helpful at all, so if anyone can shed any light on this it might start to point me in the right direction, but I’m stumped.

One of the offending examples is:

$html = preg_replace('@<script[^>]*?.*?</script>@siu', '', $html);

but as I said, this works 90% of the time.

  • 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-20T01:39:20+00:00Added an answer on May 20, 2026 at 1:39 am

    Don’t parse HTML with regex. Use a real DOM parser:

    $dom = new DOMDocument;
    $dom->loadHTML($html);
    $scripts = $dom->getElementsByTagName('script');
    while ($el = $scripts->item(0)) {
        $el->parentNode->removeChild($el);
    }
    $html = $dom->saveHTML();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML file upload field from which I'm reading the file name
I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after
I was reading about data driven testing using mbunit from this article. http://blog.benhall.me.uk/2007/04/mbunit-datafixture-data-driven-unit.html I
I am bit confusion on reading the books html 5 and jQuery. which one
I was reading this today: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#default-parameter-values and I can't seem to understand what's happening
I was reading through this article: http://aws.typepad.com/aws/2008/12/running-everything-on-aws-soocialcom.html And I was wondering if this was
I've been reading through quite a few articles on the 'this' keyword when using
I am reading in HTML from a file and displaying it on a web
I'm having a peculiar issue. I'm reading the HTML from a div contenteditable, and
I'm reading a HTML file from SDCard with browserfield (API 5.0) BrowserFieldConfig config =

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.