9/14/2011

Replace MS Word Non-Breaking Space with PHP

Microsoft Word allows people to enter a special, hidden non-breaking (nonbreaking) or no-break space character which is very difficult to recognize when one tries to find and replace unnecessary blank spaces with PHP code.

To verify that the characters are not regular spaces, try looking at the original Word document with hidden characters showing. (In MS Word 2007, this is done on the ribbon under: [Home] tab > Paragraph > click on paragraph character.) It will appear as a small circle, like a degree mark.

To replace the character using PHP, with a regular space, you should use something like this to replace the non-breaking space Unicode character:

    $story_text = preg_replace ("/\x{00A0}/", " ", $story_text);

3 comments :

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete