We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2327
    • 214 Posts
    Thank you Sottwell !

    In fact, it is not the code which you use. But yours has three differences compared to the last version of Page TOC.

    Certainly the source of the error:

    Line 203 :

    Your :
    preg_match_all($tag_pattern, $header_tags[$i], $tag1, PREG_SET_ORDER);

    The last author code :

    preg_match_all(’tag_pattern, $header_tags[$i], $tag1, PREG_SET_ORDER);



    Line 306:

    Your :
    $display_content = $display_content .array_shift($h6);

    The last author code :

    $display_content = $display_conte’t .array_shift($h6);


    Line 306:

    Your :
    $source = ereg_replace("<!--#toc_plugin#_TOC_OUTPUT-->", $display_content, $modx->documentOutput);

    The last author code :

    $source = ereg_replace("<!--#toc_plugin#_TOC_OUTPUT-->", $display_content, $source);

    If I understand well (but I understand nothing there…) it is especially this last line which posed problem.

    I warn the author shocked. Thank you very much Sottwell smiley !
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Ah, sorry about that $modx->documentOutput line, I was playing around with it and accidentally left that there. The $source variable will work just as well.

      The str_replace versus ereg_replace is just a matter of using the most efficient code. If you aren’t using any regular expressions in the replacement, str_replace is much more efficient.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 2327
        • 214 Posts
        Thank you Sottwell. So the problem was in line 203 ?!

        What is exactly a "regular expression" ?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          $search_content = '/[^|]('.$start_tag.')(.+?)('.$end_tag.')/sim';
          preg_match($search_content, $source, $actual_source);
          $content = $actual_source[0];
          

          Here preg_match (related to ereg) (ereg_replace or preg_replace does replacing) is used properly. The $search_content definition contains a regular expression
          /[^|]('.$start_tag.')(.+?)('.$end_tag.')/sim

          It’s a code for exactly what to search for. All those symbols mean something in a regular expression. Learning how to use them is a whole project in itself. Then there are the native PHP regular expressions (ereg_whatever) and perl-style regular expressions (preg_whatever), so it gets real complicated.

          http://il.php.net/ereg
          http://il.php.net/manual/en/reference.pcre.pattern.syntax.php
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org