Thoughts, rants and commentary from a husband, father of five and professional web geek

This was a little embarassing

Posted on August 14th, 2007 in General | No Comments »

NOTE: The space condition has been removed as part of the temporary fix for this problem – see below.

Yesterday I was doing some testing on my Wordpress installation. I have a problem (that others have as well) where when I post PHP code, even in the syntax highlighter, the opening PHP tag gets split between the less than symbol (<) and the question mark (?).

An example of this can be seen here:
// some PHP
?>

See the space? This only happens after the post is made. Here it is inside of code tags:
// some PHP inside code tags
?>

Even with the syntax highlighter, it still does it:

<?php
// some PHP inside of wp-syntax
?>

So far it has been added to the Wordpress forums several times. My most recent post seems to have touched off a little bit of action. We’ll see how that goes.

Anyway, I had to edit this because it was just a test page yesterday. Today, it is a fell fledged, broken PHP tag post.

I AM TESTING A CHANGE I MADE TO WP-INCLUDES/FORMATTING.PHP (balanceTags):
// test
?>

Ok, so here is the fix I implemented in my Wordpress code:

  1. Open wp-includes/formatting.php
  2. At or around line 448 (in the balanceTags function) locate regular expression number 1
  3. Change that regular expression the one in regular expression number 2
  4. Save formatting.php and upload it.
Regular expression number 1
Change from this:
"/<(\/?\w*)\s*([^>]*)>/"

Regular expression number 2
Change to this
"/<(\/?[^?]\w*)\s*([^>]*)>/"

Test the fix by trying to post:

<?php
// I are likes fixin' stuff
$myWordpress = str_replace('broken', 'fixed', $wordpress);
?>
// New test
echo 'This is a test';
Back to top