Data from MySql. I used nl2br() for line breaks, but wanted paragraph breaks.
I wrote

function test($text) { 
$text = ereg_replace("\n", "<p> ", $text ); 
return $text ;  
}

That worked but my editor wants indents not spaces between paragraphs. I thought

function test($text) { 
$text = ereg_replace("\n", "<br / ><I want to print a blank space here> ", $text ); 
return $text ;  
}

But can't figure out how to do that. Any Ideas?
Thanks

To indent text you want to use css

ie,

function test($text) {
$text = ereg_replace("\n", "<p style=\"text-indent: 20px\"> ", $text );
return $text ;
}

That will indent the first line

To indent it all

function test($text) {
$text = ereg_replace("\n", "<p style=\"padding-left:20px"\"> ", $text );
return $text ;
}

There's afew different ways of indenting it using css

Thanks for the reply Steven.
I tried the "indent all" code and just got a blank page.
in the mean time I came up with

function test($text) { 
$text = ereg_replace("\n", "<br>&nbsp; ", $text ); 
return $text ;  
}

This gives me what I want, except the first line. I'll take a look at your suggestion and try to see why it's breaking my page, as it may be a better way of accomplishing it.
Mark

Just looking at my code again, it's best you don't use it. It leaves alot of open tags.
The way you have chosen is probably best.

It probably doesn't work for the first line because you're using "\n" which is a "new line" so if it's at the beginning, there most likely isn't a new line there to replace.

OK
To address the issue of the first line, I thought "&nbsp" might be as easy as it was to resolve the rest of it. Not so. Here's what I have

function test($text) { 
$text = ereg_replace("\n", "<br>&nbsp; ", $text ); 
return $text ;  
}
<?php  $row_rsMyTable['Field'] = test ($row_rsMyTable['Field']); ?>
<?php echo "&nbsp\"" .  $row_rsMyTable['Field'] . \""; ?>

It works, except I get " at the begining of every story. Take out the " and it breaks the code.

<?php echo "&nbsp\"" .  $row_rsMyTable['Field'] . \""; ?>

It works, except I get " at the begining of every story. Take out the " and it breaks the code.

Remove the \"
Also I can't see why you have a \"" at the end, this should work.

<?php echo "&nbsp " .  $row_rsMyTable['Field']; ?>

Make sure there's a space after the &nbsp

Thanks Steven
I don't know why either. I've tried countless scenarios and thought this was one of the first.
Anyway, Thank You.
That did the trick.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.