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 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

Related Questions

Just getting going with iPhone development and Objective-C . Yesterday I was trying to
Yesterday I added some indexes on a view in my MSSQL 2008 db. After
Yesterday, I had programmed a simple Bluetooth network for my iPhone application. This morning,
Yesterday I did a production simulation. The results where not good. The connection between
Yesterday I tried to use the client side of the RestEasy framework. The interface
Yesterday I was perfectly able to debug a rails application using Netbeans 6.9.1 (just
Yesterday experts advised using while not terminated do begin... in thread execute function to
Yesterday, I've downloaded and install the free trial version of WAS v7. The version
yesterday I got some help here to get the regular expression right to accept
Yesterday I asked a question here about a oneliner and mjschultz gave me an

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.