WordPress.org

Forums

Inline PHP
WP Strips Reg Exp backslash \ from post (5 posts)

  1. philit
    Member
    Posted 3 years ago #

    In the darkest depths of WordPress there is a file called formatting.php it contains a function called wpautop(...) and the code within it is affecting the ability of the Inline PHP plugin to execute PHP regular expressions.

    The advanced example quoted on the WordPress Inline PHP plugin page… doesn’t work.

    On WP 3.2.1 used on my site all ‘\’ backslashes are stripped from each post wherever they occur!

    In order to get just one backslash to appear and be saved to the database you have to type in 4 backslashes \\\\

    On my site the following test turns out like:

    To demonstrate the effect of backslash stripping I have noticed that after every fourth backslash one is ‘escaped’ and remains;

    As a reference the first block comprises backslashes written into the posts using the \ HTML code, thats why they are not stripped out.

    1 \
    2 \\
    3 \\\
    4 \\\\
    5 \\\\\
    6 \\\\\\
    7 \\\\\\\
    8 \\\\\\\\
    9 \\\\\\\\\
    10 \\\\\\\\\\
    11 \\\\\\\\\\\
    12 \\\\\\\\\\\\

    The second block was written using the backslash character itself and as you can see as the backslash count increases to 4 one backslash is written out and stored in the database. Note that if the post is subsequently saved for any reason ALL the backslashes will be stripped out of the version before it is saved to the database.

    1
    2
    3
    4 \
    5 \
    6 \
    7 \
    8 \\
    9 \\
    10 \\
    11 \\
    12 \\\

    inline PHP works but only partially and not with backslashes which all get removed.

  2. philit
    Member
    Posted 3 years ago #

    Fixed sort of

    A plugin called Universal Post Manager (UPM) was the culprit, after de-activating it the backslashes were no stripped from posts.

    The second advanced inline PHP example worked but not without some WordPress features appearing:

    The line
    if (preg_match('/<p>.*<\/p>/ums', $filestr, $matches))
    after saving becomes
    if (preg_match('/<p>.*< \/p>/ums', $filestr, $matches))

    If you look carefully at the second line you will see a space has appeared in the </p> HTML delimiter. This changes the search pattern and effects the text returned from the file. HTML paragraph tags outside preg_match are are not interfered with at all.

    The net result is that although you can get the file, read its contents, nothing is written out in because there is no instance of < /p> specified in the WP adulterated regexp string

    WordPress post formatting is off the hook for backslashes but not for HTML tag processing just yet.

  3. philit
    Member
    Posted 3 years ago #

    Correction

    The net result is that although you can get the file specified in the advanced example url, read its contents, nothing is written out because there is no instance of the WP adulterated regexp string < /p> in the page source text.

  4. philit
    Member
    Posted 3 years ago #

    Note 03-01-2012: Tried adding a backslash escape in front of the second < character. I did so because the WP post formatting was probably inadvertently recognising '<\/p' character sequence and processing it. Escaping with a backslash stops this. '\<\/p'

    if (preg_match('/<p>.*\<\/p>/ums', $filestr, $matches))
    to
    if (preg_match('/<p>.*\<\/p>/ums', $filestr, $matches))
    

    It seemed to work as you can see from the appearance of the external page at "Plugin – Inline PHP – The Backslash Affair in WordPress"

    Please note the automatic XHTML correction feature was turned off to get this example working, this played havoc with the normal WP theme structure.
    </p>

  5. philit
    Member
    Posted 3 years ago #

    Correction to Note 03-01-2012:

    First line in code box should be without the additional backslash escape.

    if (preg_match('/<p>.*<\/p>/ums', $filestr, $matches))
    to
    if (preg_match('/<p>.*\<\/p>/ums', $filestr, $matches))
    

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Inline PHP
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags