Re: Text Format ALL GONE ??!!

From: Date: Mon, 05 Aug 2002 17:29:59 +0000
Subject: Re: Text Format ALL GONE ??!!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111230@lists.php.net to get a copy of this message
In article <20020805140434.30109.qmail@pb1.pair.com>, ohmysam@hotmail.com (Samura1) wrote: > I have a variable $text contains a paragraph and dot points. Here is an > example > ========== > Hello, > Yes I am a GUY. > Why not? > - ABC > - DEF > ========== > > But the browser will only display something like: > ========================== > Hello,Yes I am a GUY.Why not? > ========================== > > I know it is caused by the <p> <br>...etc. But how to insert this tags into > the paragraph? > Please help~ There are two ways to do this, depending on how you think of that text. If that text is meant to specifically not be HTML, nor even a paragraph, and you want to present it as flat, mono-spaced text, you can use the <pre> tag: echo "<pre>$text</pre>"; will keep the exact (monospaced) formatting. If you mean to present it as a paragraph, or as a set of paragraphs and listed items, you'll need to do it in multiple steps. 1. Break it into an array of paragraphs, probably using the 'split' function. 2. Iterate through each paragraph and echo "<p>$paragraph</p>"; (assuming that you use $paragraph as your iteration variable). This ignores that some of your paragraphs are really list items. Don't worry about that. Make sure that those steps are working, and then: 3. If they are indented as a list, as it appears, you'll want to detect that they are a list, and then (a) drop the pre-pended spaces, (b) drop the bullet (-), and (c) echo "<li>$listitem</li>. Making sure to always use "<ul>" along with the first list item and "</ul>" with the final list item. Do step 3 last, because it is the most complicated! Get the first two steps done first. Jerry -- http://www.hoboes.com/jerry/ "Give a man a fish and you feed him for a day. Teach him to fish, and you've depleted the lake."--It Isn't Murder If They're Yankees (http://www.hoboes.com/jerry/Murder/)

« previous php.general (#111230) next »