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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:10:34+00:00 2026-05-12T15:10:34+00:00

Yesterday I tracked down a strange bug which caused a website display only a

  • 0

Yesterday I tracked down a strange bug which caused a website display only a white page – no content on it, no error message visible.

I found that a regular expression used in preg_replace was the problem.

I used the regex in order to replace the title html tag in the accumulated content just before echo´ing the html. The html got rather large on the page where the bug occured (60 kb – not too large) and it seemed like preg_replace / the regex used can only handle a string of certain length – or my regex is really messed up (also possible).

Look at this sample program which reproduces the problem (tested on PHP 5.2.9):


function replaceTitleTagInHtmlSource($content, $replaceWith) {
  return preg_replace('#(<title>)([\s\S]+)(<\/title>)#i', '$1'.$replaceWith.'$3', $content);
}


$dummyStr = str_repeat('A', 6000);

$totalStr = '<title>foo</title>';

for($i = 0; $i < 10; $i++) {
  $totalStr .= $dummyStr;
}

print 'orignal: ' . strlen($totalStr);
print '<hr />';

$replaced = replaceTitleTagInHtmlSource($totalStr, 'bar');

print 'replaced: ' . strlen($replaced);
print '<hr />';

Output:

orignal: 60018
replaced: 0

So – the function gets a string of length 60000 and returns a string with 0 length. Not what I wanted to do with my regex.


Changing

for($i = 0; $i < 10; $i++) {

to

for($i = 0; $i < 1; $i++) {

in order to decrease the total string length, the output is:

orignal: 6018
replaced: 6018


When I removed the replacing, the content of the page was displayed without any problems.

  • 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-12T15:10:34+00:00Added an answer on May 12, 2026 at 3:10 pm

    It seems like you’re running into the backtracking limit.

    This is confirmed if you print preg_last_error(): it returns PREG_BACKTRACK_LIMIT_ERROR.

    You can either increase the limit in your ini file or using ini_set() or change your regular expression from ([\s\S]+) to .*?, which will stop it from backtracking so much.

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

Sidebar

Ask A Question

Stats

  • Questions 218k
  • Answers 218k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Removing the namespace declaration from the top node makes the… May 12, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer This is similar to AST from C code If your… May 12, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer It is not a requirement. The cookie will get associated… May 12, 2026 at 11:35 pm

Related Questions

Yesterday I wanted to add a boolean field to an Oracle table. However, there
Yesterday I was having a heated debate with a coworker on what would be
Yesterday I thought it would be nice to implement my own Trigger in a
Yesterday I got a call from a Microsoft representative asking if we supply hosted

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.