Jump to content


Photo

How do i not remove the spaces?


  • Please log in to reply
8 replies to this topic

#1 Wes1890

Wes1890
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts

Posted 03 November 2005 - 02:51 PM

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
AND THEN GOD HIMSELF BESTOWED HIS HAND UPON PHPFREAKS...

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 03 November 2005 - 05:49 PM

browsers ignore spaces and newlines. they're in the source but they're not displayed. surround the text with <pre> </pre>, or use &nbsp; and <br>
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 Wes1890

Wes1890
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts

Posted 03 November 2005 - 07:27 PM

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>&nbsp;</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?
AND THEN GOD HIMSELF BESTOWED HIS HAND UPON PHPFREAKS...

#4 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 03 November 2005 - 07:44 PM

you should use str_replace instead of strtr. and use nl2br to convert newlines to br
$message_line=str_replace(' ','&nbsp;',nl2br($message));

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#5 Wes1890

Wes1890
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts

Posted 03 November 2005 - 09:55 PM

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?
AND THEN GOD HIMSELF BESTOWED HIS HAND UPON PHPFREAKS...

#6 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 03 November 2005 - 10:30 PM

the answer lies in what you wanna do: wordwrap()
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#7 Wes1890

Wes1890
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts

Posted 04 November 2005 - 12:32 AM

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(' ','&nbsp;',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?
AND THEN GOD HIMSELF BESTOWED HIS HAND UPON PHPFREAKS...

#8 Wes1890

Wes1890
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts

Posted 04 November 2005 - 11:22 PM

*bump*

:)
AND THEN GOD HIMSELF BESTOWED HIS HAND UPON PHPFREAKS...

#9 Wes1890

Wes1890
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts

Posted 05 November 2005 - 12:51 AM

Ohh.. i fixed it..

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

Thanks ryan
AND THEN GOD HIMSELF BESTOWED HIS HAND UPON PHPFREAKS...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users