Jump to content

Archived

This topic is now archived and is closed to further replies.

Wes1890

How do i not remove the spaces?

Recommended Posts

I've got a CMS system on my site... and last nite before I went to bed, i posted myself a reminder to do something bla bla bla... well, posted something like this:

 

Well i'm off to bed...            it's 3:20am!

 

This is also a reminder to FIX THE MEMCP FILE!!

 

well, the problem is, it shows up like this:

Well i'm off to bed... it's 3:20am! This is also a reminder to FIX THE MEMCP FILE!!

 

It removes the "newlines" and the multiple spaces.... how would i have it keep them?

 

Big thanks

Share this post


Link to post
Share on other sites

browsers ignore spaces and newlines. they're in the source but they're not displayed. surround the text with <pre> </pre>, or use   and <br>

Share this post


Link to post
Share on other sites

The original message is this:

bla bla bla bla bla

 

poo

 

The <pre> idea works, but disables the word wrap that the browser has default...

 

Using <b>strtr()</b> i replaced all spaces with <b> </b> and replaces all lines with <br />... but the message came out something like this:

bla&bla&bla&bla&bla

 

So, for the lines i put

$message_line = strtr($message,"","

");

 

Which made

bla bla bla bla bla

poo

(poo only went down 1 line.. instead of the original 2)

 

 

Thanks for the reply... but any more ideas?

Share this post


Link to post
Share on other sites

you should use str_replace instead of strtr. and use nl2br to convert newlines to br

$message_line=str_replace(' ',' ',nl2br($message));

Share this post


Link to post
Share on other sites

I knew there was a string replace function.... but i used strreplace by mistake... thanks a bunch..

 

 

But now there is another problem (figures...)

 

The text inside the tables do not wrap, even when i shrink the width of the tables.

 

Is there a way to wrap text? Or is there a way to count an amount of characters (length) and have it make a new line after there are so many letters? (without cutting words in half)

 

^Big thanks to you man.. but what about word wrapping?

Share this post


Link to post
Share on other sites

It isn't working for some reason... ???

 

This is the code ($message is what needs wrapped... also, language filter is my own function, just ignore it)

// Display the news

while($r=mysql_fetch_array($getnews))

{

  extract($r); // Put DB info as VARS

  $title = stripslashes($title); // Strip slashes

  $message = stripslashes($message); // Strip slashes

  $message_line = str_replace(' ',' ',nl2br($message)); // Make new lines

  $message_clean = language_filter($message_line); // Filter the language

  $message_wrap = wordwrap($message_clean, 20, "<br />\n"); // Wrap the message

  $final_message = $message_wrap; // The final piece

 

  echo "Message: {$final_message}";  // Show the message

}

 

 

Why wont it work?

Share this post


Link to post
Share on other sites

Ohh.. i fixed it..

 

I had to have the nl2br function AFTER the wrap command... :)

 

Thanks ryan

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.