p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: how to add line breaks between paragraphs


Message #1 by Bernardo Zuniga <bzuniga@n...> on Fri, 27 Sep 2002 17:01:19 -0400
hi everyone,

I was wondering if anyone knew how to create line breaks or returns in 
a block of text that is pulled from a database field. basically, I need 
to form the text back into paragraphs of a news story. i know that I 
can split a string up or insert characters at a separator, but I can't 
use the periods since there are more sentences per paragraphs than one. 
Do I have to insert a character at the end of the paragraph to use for 
a split?

Any help is appreciated,
Bernardo

Message #2 by "David Scott-Bigsby" <DScott-Bigsby@P...> on Fri, 27 Sep 2002 14:18:46 -0700
> I was wondering if anyone knew how to create line breaks or
> returns in a block of text that is pulled from a database field.
> basically, I need
> to form the text back into paragraphs of a news story. i know that I
> can split a string up or insert characters at a separator,
> but I can't use the periods since there are more sentences per 
paragraphs
> than one.
> Do I have to insert a character at the end of the paragraph
> to use for a split?

Presumeably the paragraphs have some sort of separator in their "raw" 
form in the database. What is it?

dsb

***************************************       
David Scott-Bigsby
Product Manager, Web Site and PEDN

PureEdge Solutions
The Leader in Secure XML e-Forms

v:250-708-8145  f:250-708-8010
1-888-517-2675   www.PureEdge.com
***************************************
Message #3 by Bernardo Zuniga <bernardo@e...> on Fri, 27 Sep 2002 17:34:58 -0400
I tried to insert \n since I know that adds break when outputting to 
the browser, but that had no effect when it was returned from the 
database. Is there a way to find out what it is in it's raw form?
On Friday, September 27, 2002, at 05:18 PM, David Scott-Bigsby wrote:

>> I was wondering if anyone knew how to create line breaks or
>> returns in a block of text that is pulled from a database field.
>> basically, I need
>> to form the text back into paragraphs of a news story. i know that I
>> can split a string up or insert characters at a separator,
>> but I can't use the periods since there are more sentences per 
>> paragraphs
>> than one.
>> Do I have to insert a character at the end of the paragraph
>> to use for a split?
>
> Presumeably the paragraphs have some sort of separator in their "raw" 
> form in the database. What is it?
>
> dsb
>
> ***************************************
> David Scott-Bigsby
> Product Manager, Web Site and PEDN
>
> PureEdge Solutions
> The Leader in Secure XML e-Forms
>
> v:250-708-8145  f:250-708-8010
> 1-888-517-2675   www.PureEdge.com
> ***************************************
>
>

Message #4 by "David Scott-Bigsby" <DScott-Bigsby@P...> on Fri, 27 Sep 2002 15:04:46 -0700
> I tried to insert \n since I know that adds break when outputting to
> the browser, but that had no effect when it was returned from the
> database. Is there a way to find out what it is in it's raw form?

HTML turns any stretch of whitespace characters (including new lines and 
tabs) into a single space, so it's effects on formatting is pretty 
limited.

The good news is that you can use a replace function to find "\n" in the 
text and replace it with "<P>".

The bad news is that, to make good HTML, the paragraph should be wrapped 
in "<P></P>". What you probably want to do, then, is to replace "\n" 
with "</P><P>", and then place the string within "<P></P>", e.g., echo 
"<P>$newsstory</P>";

dsb

***************************************       
David Scott-Bigsby
Product Manager, Web Site and PEDN

PureEdge Solutions
The Leader in Secure XML e-Forms

v:250-708-8145  f:250-708-8010
1-888-517-2675   www.PureEdge.com
***************************************
Message #5 by Bernardo Zuniga <bernardo@e...> on Fri, 27 Sep 2002 18:33:13 -0400
Is there some way to use urlencode and urldecode to do the same thing. 
i would just have to look for the line break in the string. The 
question is how do I tell it to insert  <br> in place of the 
urlencoding?
On Friday, September 27, 2002, at 06:04 PM, David Scott-Bigsby wrote:

>> I tried to insert \n since I know that adds break when outputting to
>> the browser, but that had no effect when it was returned from the
>> database. Is there a way to find out what it is in it's raw form?
>
> HTML turns any stretch of whitespace characters (including new lines 
> and tabs) into a single space, so it's effects on formatting is pretty 
> limited.
>
> The good news is that you can use a replace function to find "\n" in 
> the text and replace it with "<P>".
>
> The bad news is that, to make good HTML, the paragraph should be 
> wrapped in "<P></P>". What you probably want to do, then, is to 
> replace "\n" with "</P><P>", and then place the string within 
> "<P></P>", e.g., echo "<P>$newsstory</P>";
>
> dsb
>
> ***************************************
> David Scott-Bigsby
> Product Manager, Web Site and PEDN
>
> PureEdge Solutions
> The Leader in Secure XML e-Forms
>
> v:250-708-8145  f:250-708-8010
> 1-888-517-2675   www.PureEdge.com
> ***************************************
>
>

Message #6 by Bernardo Zuniga <bernardo@e...> on Fri, 27 Sep 2002 21:03:01 -0400
I figured out a solution!
basically, I run the query from the data base and since it is running a 
loop to output all the rows, in the place where I am outputting the 
text that needs to be formatted, i use the explode() function to apply 
formatting.

This is the code if anyone can use this:
// run the db_connect and build a query in $query
$result = mysql_query($query,$link);

//this is the loop to output the dynamic table
while($my_row = mysql_fetch_array($result)) {

//this is the part that formats the out put text
//typing into a form field/text area and hitting return automatically 
adds the return as \n, you can use that as a split character
	$pieces = explode("\n",$my_row['body']);
	foreach($pieces as $value) {
	echo "<p align='justify'>";
	echo "$value<br>";
	echo "</p>\n";
	}
	//this horizontal rule is used as a separator for the text
	echo "<hr>";
}

next step would be to make this a function for neatness.
Thanks to everyone for the help and if anyone has any suggestions about 
this please let me know.
Bernardo
On Friday, September 27, 2002, at 06:33 PM, Bernardo Zuniga wrote:

> Is there some way to use urlencode and urldecode to do the same thing. 
> i would just have to look for the line break in the string. The 
> question is how do I tell it to insert  <br> in place of the 
> urlencoding?
> On Friday, September 27, 2002, at 06:04 PM, David Scott-Bigsby wrote:
>
>>> I tried to insert \n since I know that adds break when outputting to
>>> the browser, but that had no effect when it was returned from the
>>> database. Is there a way to find out what it is in it's raw form?
>>
>> HTML turns any stretch of whitespace characters (including new lines 
>> and tabs) into a single space, so it's effects on formatting is 
>> pretty limited.
>>
>> The good news is that you can use a replace function to find "\n" in 
>> the text and replace it with "<P>".
>>
>> The bad news is that, to make good HTML, the paragraph should be 
>> wrapped in "<P></P>". What you probably want to do, then, is to 
>> replace "\n" with "</P><P>", and then place the string within 
>> "<P></P>", e.g., echo "<P>$newsstory</P>";
>>
>> dsb
>>
>> ***************************************
>> David Scott-Bigsby
>> Product Manager, Web Site and PEDN
>>
>> PureEdge Solutions
>> The Leader in Secure XML e-Forms
>>
>> v:250-708-8145  f:250-708-8010
>> 1-888-517-2675   www.PureEdge.com
>> ***************************************
>>
>>
>
>
> ---
> Change your mail options at http://p2p.wrox.com/manager.asp or to 
> unsubscribe send a blank email to 
>

Message #7 by "jorge" <jorge@d...> on Sun, 29 Sep 2002 10:21:37 -0500
Hola Bernardo:
The solution lies on the way you are loading your data  MYSQL you have LOAD
DATA statement wich allowys you to define the import options of the file, so
you can define the 'char' that will be recognized as break
everything that you define in the import options will be availabel in the
export.
 LOAD DATA LOCAL INFILE myfile.txt INTO TABLE mytable FIELDS TERMINATED BY
'string'

Saludos from Mexico

Jorge Cordero


hopes this help

----- Original Message -----
From: "Bernardo Zuniga" <bzuniga@n...>
To: "beginning php" <beginning_php@p...>
Sent: Friday, September 27, 2002 4:01 PM
Subject: [beginning_php] how to add line breaks between paragraphs


> hi everyone,
>
> I was wondering if anyone knew how to create line breaks or returns in
> a block of text that is pulled from a database field. basically, I need
> to form the text back into paragraphs of a news story. i know that I
> can split a string up or insert characters at a separator, but I can't
> use the periods since there are more sentences per paragraphs than one.
> Do I have to insert a character at the end of the paragraph to use for
> a split?
>
> Any help is appreciated,
> Bernardo
>
>


Message #8 by "jorge" <jorge@d...> on Sun, 29 Sep 2002 10:27:45 -0500
hey i should have wrriten 'string' instead of 'char' sorry for mistake

Jorge

----- Original Message -----
From: "jorge" <jorge@d...>
To: "beginning php" <beginning_php@p...>
Sent: Sunday, September 29, 2002 10:21 AM
Subject: [beginning_php] Re: how to add line breaks between paragraphs


> Hola Bernardo:
> The solution lies on the way you are loading your data  MYSQL you have
LOAD
> DATA statement wich allowys you to define the import options of the file,
so
> you can define the 'char' that will be recognized as break
> everything that you define in the import options will be availabel in the
> export.
>  LOAD DATA LOCAL INFILE myfile.txt INTO TABLE mytable FIELDS TERMINATED BY
> 'string'
>
> Saludos from Mexico
>
> Jorge Cordero
>
>
> hopes this help
>
> ----- Original Message -----
> From: "Bernardo Zuniga" <bzuniga@n...>
> To: "beginning php" <beginning_php@p...>
> Sent: Friday, September 27, 2002 4:01 PM
> Subject: [beginning_php] how to add line breaks between paragraphs
>
>
> > hi everyone,
> >
> > I was wondering if anyone knew how to create line breaks or returns in
> > a block of text that is pulled from a database field. basically, I need
> > to form the text back into paragraphs of a news story. i know that I
> > can split a string up or insert characters at a separator, but I can't
> > use the periods since there are more sentences per paragraphs than one.
> > Do I have to insert a character at the end of the paragraph to use for
> > a split?
> >
> > Any help is appreciated,
> > Bernardo
> >
> >
>
>
>



  Return to Index