1

I am new to PHP and web design in general.

This is particularly true when it comes to CodeIgniter's PHP shorthand tools. A friend of mine who has become increasingly hard to get in touch with due to her "day job" has made updating, editing this site a pretty large learning curve. She was also the one who wrote the original code for this site a couple years ago. Fast forward to today. I have been on my own with it for awhile now, and I am learning a lot. However, I recently encountered an issue that I wonder if anyone could help me with:

Not too long ago my recipe site worked flawlessly on my web host. Until, I recently took a copy of the files and database offline into a development environment to attempt to get the site ready for this major CodeIgniter 4.0.4 Upgrade rolling out from CodeIgniter. I rarely edit anything that builds or drives the site due to my newness with PHP. However, recently I have been trying to figure out why on the web host everything works without issue. Now on the newest version of my XAMPP installation, I am getting errors that didn't exist before. I have a suspicion that something between PHP 7.3.6 and PHP 7.4.8 has been changed. I did fix all my curly brace errors early on after PHP notified me that those had been deprecated.

I have scoured the web trying to find a solution to this issue but none of the issues I found, quite matched mine. I get the following error:


A PHP Error was encountered

Severity: Warning

Message: preg_replace_callback(): Compilation failed: quantifier does not follow a repeatable item at offset 397

Filename: libraries/Mkdn.php

Line Number: 529

Backtrace:

File: C:\xampp\htdocs\shirleysrecipesupdate\application\libraries\Mkdn.php
Line: 529
Function: preg_replace_callback

File: C:\xampp\htdocs\shirleysrecipesupdate\application\libraries\Mkdn.php
Line: 326
Function: hashHTMLBlocks

File: C:\xampp\htdocs\shirleysrecipesupdate\application\libraries\Mkdn.php
Line: 69
Function: transform

File: C:\xampp\htdocs\shirleysrecipesupdate\application\views\recipe.php
Line: 33
Function: translate

File: C:\xampp\htdocs\shirleysrecipesupdate\application\views\includes\template.php
Line: 65
Function: view

File: C:\xampp\htdocs\shirleysrecipesupdate\application\controllers\Recipe.php
Line: 25
Function: view

File: C:\xampp\htdocs\shirleysrecipesupdate\index.php
Line: 315
Function: require_once

What "offset 397" is PHP referring to? Here is the server version info I know you might need:

Working Web Host Current Config:

CodeIgniter Version: 3.1.9
PHP Version: 7.3.6
MySQL Server Version: 5.7.27

The Development Environment Config:

CodeIgniter Version: 3.1.9
PHP Version: 7.4.8
MariaDB Server Version: 10.4.13

I have two "libraries/Mkdn.php" directories in my total application. But, I think PHP is referring to "application/libraries/Mkdn.php" based on the back-traces. So I will include that one.

/application/libraries/Mkdn.php, Line #529 Function

 function hashHTMLBlocks($text){
 if ($this->no_markup) 
  return $text;
  $less_than_tab = $this->tab_width - 1;
  
  # Hashify HTML blocks:
  # We only want to do this for block-level HTML tags, such as headers,
  # lists, and tables. That's because we still want to wrap <p>s around
  # "paragraphs" that are wrapped in non-block-level tags, such as anchors,
  # phrase emphasis, and spans. The list of tags we're looking for is
  # hard-coded:
  #
  # *  List "a" is made of tags which can be both inline or block-level.
  #    These will be treated block-level when the start tag is alone on 
  #    its line, otherwise they're not matched here and will be taken as 
  #    inline later.
  # *  List "b" is made of tags which are always block-level;
  #
  
  $block_tags_a_re = 'ins|del';
  $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. 'script|noscript|form|fieldset|iframe|math';
  
  # Regular expression for the content of a block tag.
    
  $nested_tags_level = 4;
  $attr = '
  (
   ?>           # optional tag attributes
   \s           # starts with whitespace
   (
    ?>
    [^>"/]+     # text outside quotes
    |
    /+(?!>)     # slash not followed by ">"
    |
    "[^"]*"     # text inside double quotes (tolerate ">")
    |
    \'[^\']*\'  # text inside single quotes (tolerate ">")
   )
   *
  )
  ? 
  ';
  $content =
   str_repeat('
   (
    ?>
    [^<]+       # content without tag
    |
    <\2         # nested opening tag
     '.$attr.'  # attributes
   (?>
   />
   |
   >', $nested_tags_level). # end of opening tag
   '.*?'.                   # last level nested tag content
   str_repeat('
   </\2\s*>    # closing nested tag
   )
   |                
   <(?!/\2\s*>  # other tags with a different name
   )
   )*',
   $nested_tags_level);
   $content2 = str_replace('\2', '\3', $content);

   # First, look for nested blocks, e.g.:
   # <div>
   # <div>
   # tags for inner block must be indented.
   # </div>
   # </div>
   #
   # The outermost tags must start at the left margin for this to match, and
   # the inner nested divs must be indented.
   # We need to do this before the next, more liberal match, because the next
   # match will start at the first `<div>` and stop at the first `</div>`.
   
   $text = preg_replace_callback('{(?>
   (?>
    (?<=\n\n)                 # Starting after a blank line
     # or
     \A\n?                    # the beginning of the doc
   )
   (                          # save in $1
   # Match from `\n<tag>` to `</tag>\n`, handling nested tags 
   # in between.
   [ ]{0,'.$less_than_tab.'}
   <('.$block_tags_b_re.')    # start tag = $2
   '.$attr.'>                 # attributes followed by > and \n
   '.$content.'               # content, support nesting
   </\2>                      # the matching end tag
   [ ]*                       # trailing spaces/tabs
   (?=\n+|\Z)                 # followed by a newline or end of document
   |                          # Special version for tags of group a.
   [ ]{0,'.$less_than_tab.'}
   <('.$block_tags_a_re.')    # start tag = $3
   '.$attr.'>[ ]*\n           # attributes followed by >
   '.$content2.'              # content, support nesting
   </\3>                      # the matching end tag
   [ ]*                       # trailing spaces/tabs
   (?=\n+|\Z)                 # followed by a newline or end of document
   |                          # Special case just for <hr />. It was easier to make a special 
                              # case than to make the other regex more complicated.
   [ ]{0,'.$less_than_tab.'}
   <(hr)                      # start tag = $2
   '.$attr.'                  # attributes
   /?>                        # the matching end tag
   [ ]*
   (?=\n{2,}|\Z)              # followed by a blank line or end of document
   |                          # Special case for standalone HTML comments:
            
   [ ]{0,'.$less_than_tab.'}
   (?s:
   <!-- .*? -->
   )
   [ ]*
   (?=\n{2,}|\Z)              # followed by a blank line or end of document
            
   |                          # PHP and ASP-style processor instructions (<? and <%)
            
   [ ]{0,'.$less_than_tab.'}
   (?s:
   <([?%])                    # $2
   .*?
   \2>
   )
   [ ]*
   (?=\n{2,}|\Z)              # followed by a blank line or end of document
   )
   )}Sxmi',
   array(&$this, '_hashHTMLBlocks_callback'), 
   $text);                   # This is line #529
   return $text;
}

I hope that helps. If you need to see more of the dependencies I will happy to post those as well. Thank you in advance!

  • Is this periodic or across the board? Did it just start doing it or has it always been doing it from the start? My one guess is that the HTML being provided to it doesn't match the expected pattern, so for debugging purposes I would capture that HTML and inspect it. HTML and RegEx, except in for controlled environments, [often don't mix well](https://stackoverflow.com/a/1732454/231316) in the long run. – Chris Haas Jul 28 '20 at 13:13
  • Thank you for your response. This issue only presents on one section of the site. I have used this development environment several times in the past and have never had this kind of error before. This is what spurred my post. I will inspect the HTML for errors and get back to you. –  Jul 28 '20 at 16:00
  • I have inspected the HTML and see no erroneous code with the exception of the already posted error code. Hope that helps. –  Jul 28 '20 at 17:18

0 Answers0