FCKeditor   after capital letters and colonsFCKeditor   after capital letters and colons

Posted January 7th, 2009 in FCKEditor and PHP

I use FCKEditor on my content driven websites to write the content. In version 2.6.3 I have found that the editor inserts   characters after capital letters and the colon character, and I don't want this behaviour. This post shows a server-sided solution to the problem using PHP.

The issue doesn't appear to occur after all capital letters but always appears to do it after capital I and after colons. It doesn't appear to occur in FCKEditor 2.6.2 (which I have installed on this blog - I have 2.6.3 on my newer blogs and haven't yet upgraded this one).

I couldn't find anything in the configuration options which would switch this behaviour off. The FillEmptyBlocks configuration option doesn't affect this particular issue, and isn't really one you'd want to switch off anyway.

Here's an example of some text that I entered into the editor:

On this line I will be followed by a non-breaking space.
On this line the word GUI will be followed by a non-breaking space.
This is a list: this is item one; this is item two.

You would expect the source to look like this:

<p>On this line I will be followed by a non-breaking space.</p>
<p>On this line the word GUI will be followed by a non-breaking space.</p>
<p>This is a list: this is item one; this is item two.</p>

But it actually looks like this (I've marked the &nbsp; in red):

<p>On this line I&nbsp;will be followed by a non-breaking space.</p>
<p>On this line the word GUI&nbsp;will be followed by a non-breaking space.</p>
<p>This is a list:&nbsp;this is item one; this is item two.</p>

Note that when the paragraph starts with the letter I it doesn't always put a non-breaking space after it.

As I mentioned above I couldn't find a configuration option in the Javascript configuration which would solve this issue, so instead resorted to a PHP regular expression on the server-side to fix it. I don't want to replace all &nbsp; with a space - just those after capital letters and colons, so we need to use a regular expression instead of a straight str_replace.

If the html is stored in the $html variable in the code below, the regexp would look like this:

$html = preg_replace('/([A-Z:])&nbsp;/', '\\1 ', $html);

The ([A-Z:])&nbsp; bit matches capital letters A to Z and colons which are followed by &nbsp;

The matches are then replaced with the [A-Z:] part followed by a regular space. The \\1 matches the stuff in the brackets in the first parameter.

Related posts:

Comments

blog comments powered by Disqus