I thought that it was 0.

I am trying to take formatted text (hince multiple spaces & linefeeds) and change it to formatted HTML (hince &nbsp; and <BR>).

so the string

"1             2           3          4
5             6           7          8"

Will look like

"1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4<BR>5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8"

I have the carriage returns down fine but i am having trouble with the spaces.

I am using the following code:

$message =str_replace(chr(13), "<BR>", $message);

$message =str_replace(chr(0), "&nbsp;", $message);

any help will be greatly appreciated.

    Well, &nbsp; isn't exacly ASCII value for a space, but it makes NoBreakingSPace 🙂 and it should display like you wanted...

    $message = str_replace(chr(0), "&nbsp;", $message);

    Hope it helps, Arni

      I am a idiot. I have those in there they just displayed as spaces since this message board is viewed as html. Duh! The problem isnt a single space thats covered. It is consecutive multiple spaces. The piece of code you gave i am already using but it isnt working i need an alternate method.

        the code isnt replacing the chr(0) with the nbsp at all otherwise yes it would work

          Why not just:
          $message = str_replace(" ", "&nbsp;", $message); ?

            Try
            $string = ereg_replace( '[[:space:]]+', '\&nbsp;', $string );

            Something like that should work

              you mentioned nbsp in a post? I presume you mean &nbsp;, otherwise it won't work, it the above gives a space...

              & n b s p ; without the spaces :-)

                The ascii value for space is 32 (decimal) or 20 (hex)

                  Thanks gentleman i have it working now i used the code i had and changed the ascii value to 32 at Ken's suggestion. I also like the ereg replace function but i dont feel comfortable with it. I just need to learn how to make it work.

                  Thanks Again everyone

                    ASCII equivalent is 0x20 (hex) or 32 decimal.

                    ArniHr wrote:

                    Well, &nbsp; isn't exacly ASCII value for a space, but it makes NoBreakingSPace 🙂 and it should display like you wanted...

                    $message = str_replace(chr(0), "&nbsp;", $message);

                    Hope it helps, Arni

                      Write a Reply...