Jump to content

formatting text?


astralaaron

Recommended Posts

Hello, I am comfortable pulling arrays of data from a database. for message forms / news feeders, those types of things.I am sure there is a way, but when I output my data it doesn't format how i typed it to enter it into the database - formatted in paragraphsand what not.. I am guessing people here already know what I am talking about so I will stop the explanation right there.A

Link to comment
Share on other sites

From the beginning, HTML has interpreted any combination of line breaks and empty spaces as exactly one space. On the other hand, formatting with non-breaking spaces is very inexact. You'd do better with CSS.

Link to comment
Share on other sites

From the beginning, HTML has interpreted any combination of line breaks and empty spaces as exactly one space. On the other hand, formatting with non-breaking spaces is very inexact. You'd do better with CSS.
eh this just confused me even more, thanks for trying though :)
Link to comment
Share on other sites

You can use str_replace if you want to replace spaces with " ". The text might come out a little strange though if it only wraps on newlines, it will not wrap on the nbsp character.

let me get this straight. when someone pushes enter it creates an invisible \n ?
It's not invisible, when you press enter it adds a newline character. The same as tab or whatever else.
Link to comment
Share on other sites

You can use str_replace if you want to replace spaces with " ". The text might come out a little strange though if it only wraps on newlines, it will not wrap on the nbsp character.It's not invisible, when you press enter it adds a newline character. The same as tab or whatever else.
well I don't see it when I press enter so I just said invisible... of course it is there .. if enter leaves a \n what does a tab leave?.so basically what everyone is saying is there is no way to format text perfectly through php?
Link to comment
Share on other sites

Enter doesn't leave a "\n", it adds a newline character. In PHP you represent a newline character using the escape sequence "\n". In PHP a tab character is represented by "\t".

so basically what everyone is saying is there is no way to format text perfectly through php?
That depends on the definition of "perfectly".
Link to comment
Share on other sites

Enter doesn't leave a "\n", it adds a newline character. In PHP you represent a newline character using the escape sequence "\n". In PHP a tab character is represented by "\t".That depends on the definition of "perfectly".
well by perfectly, all I meant was the same way the user types it into the textfield is how it should output..
Link to comment
Share on other sites

->astralaaron It's not invisible, when you press enter it adds a newline character. The same as tab or whatever else.This is ,how I understand this .There is a few coding world when you are watching your computer ,but you are not aware of that .The World Wide Web Consortium (W3C)Tim starts work on a hypertext GUI browser+editor using the NeXTStep development environment. He makes up "WorldWideWeb" as a name for the program .http://www.w3.org/History.html-> And the www. system have a rules for writing and it not prefect like any other (create by W3C)The world of www but NeXTStep is developed by some other program wich I can't find on the web , but I will ask later a 65 years old developer man . -> the world of second language also have a bugs Assembler -> first level language world of machine codehardware , what to say ?, ->the our world .Hope this was a helpful Tell me if anything of this wrong informed .I would be pleased .

Link to comment
Share on other sites

That is how PHP outputs it. PHP outputs exactly what you type in. The problem is that HTML does not display it that way, HTML ignores whitespace. You can use the CSS white-space property to change how the browser handles whitespace:http://www.w3schools.com/css/pr_text_white-space.asp
ok now the other guys post makes sense.
Link to comment
Share on other sites

What justsomeguy typed is total true , but in which world . But in basic you need to find a answer by your self .This forum is like a little light of whole dark world . So you can see where are you going at least .

Link to comment
Share on other sites

ok well....normal didnt change anything.pre made it so the white spaces worked like I wanted BUT it did not wrap at all.. just kept going off to the right of the page, no 'newlines'and of course nowrap makes it not wrap.. and not pay attention to spaces.is there a way to make both the newline / spaces work at the same time?

Link to comment
Share on other sites

ok well....CSS Whitespace propertynormal didnt change anything.pre made it so the white spaces worked like I wanted BUT it did not wrap at all.. just kept going off to the right of the page, no 'newlines'and of course nowrap makes it not wrap.. and not pay attention to spaces.is there a way to make both the newline / spaces work at the same time?
Link to comment
Share on other sites

Okay. This works. Apparently, when preg_replace() works with arrays, it does so sequentially, which I would not have guessed. This makes possible the really sloppy regex work that I am presenting. I'm sure a talented regex genius could have done all this in a single expression. Not I.The goal is this: change every \n character into <br>. Preserve the author's desire to have multiple spaces. So change " " to " " BUT don't change single spaces to " ", and make sure that every group of multiple " " begins with a real space. This way text wrapping won't be affected.Cheers!

$string = //(whatever comes out of your textarea)$pat[0] = '/\n/';$rep[0] = '<br>';$pat[1] = '/\s/';$rep[1] = "\t";$pat[2] = '/(\S)\t/';$rep[2] = '$1 ';$pat[3] = '/\t/';$rep[3] = ' ';ksort($pat); // a precaution in case you adapt the routine so the arrays are filled unsequentiallyksort($rep);$string = preg_replace($pat, $rep, $string);echo $string; // or do something useful with it.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...