MyBB Community Forums

Full Version: Line-breaks in PHP MyCode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
if we use [PHP] MyCode, there is a problem with forum width - mybb post parser uses build-in php function to syntax highlight, but this function create text with non-breaking spaces. In effect, posts can be too wide and "damage" our forum. Also, we can't fix it using css.

I prepared small modification which change non-breaking spaces to normal spaces.

1. Open /inc/class_parser.php file.

2. Find (line ~826):

// Send back the code all nice and pretty

3. Add before:

$code = preg_replace_callback('#( )+#', array($this, 'deleteNbsp'), $code);

4. Find (end of the file):

}
?>

5. Add before:

private function deleteNbsp($text)
{ 
  return (strlen($text[0]) < 7) ? ' ' : $text[0];
}

6. Save file and upload to server replacing original.


It's all!
Pretty sure it's meant to do that so the really long lines can be copied and pasted and still work.
How weird, I remember using CSS white-space:; property to solve this before Undecided
@Alex Smith
It isn't work if you use for example one, very long word without any spaces (ex. one word with 200+ chars).

@Sama34
You can solve similar problem with [CODE] using only css. In [PHP] the situation is worse - mycode parser uses highlight_string function which replaces every space with the html code &nbsp;