CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeCharge.Discussion

 string replace /n <br>

Print topic Send  topic

Author Message
Steven Dowd
Posted: 10/21/2002, 7:25 PM

I have two large text area's in a page , and needed to clean
the page breaks text etc
so i took a look through a few of the sample CC2 codes
and found that in the gotocode example the inputted /
displayed text was being cleaned with

$fldxxxxxx = str_replace("\n", "<br>", $fldxxxxxxxxx );

so i tried it , and it worked ..... untill i clicked 'update' and it
went pearshaped, it doubled up on all the <br>'s


so what was previously:

text like this in a line
<br>with a leading break beforit
<br>like this example text

has become text that is
<br><br>formatted like this with two
<br><br>leading breaks befor each line

and if i clicked update again it gets worse
<br><br><br>it will keep adding these extra break
<br><br><br>tags for ever,

anyways, now you have had a good laugh , what can i add
to clean the html that doesnt add extra breaks on update

i did some testing and the following

$fldnews_top = str_replace("<br><br>", "", $fldnews_top );
$fldnews_top = str_replace("<br>", "", $fldnews_top );
$fldnews_top = str_replace("\n", "<br>", $fldnews_top );

works perfectly to remove all the existing 'many' <br> tags
and doesnt add any extra, so the page looks ok,

but damn thats a bad way to do it, even i can see that, so

how do i clean many breaks from my old website posts ,
but not totally kill the site by removing 'all' the <br> tags

thanks

Steven Dowd



michael weaver
Posted: 10/25/2002, 10:12 AM

Steven, there is an easier way! I went through this same thing before, btw.
In before show, use the built-in php expression nl2br()

For instance, in Before Show, do this:

$fldxxxx = nl2br($fldxxxx);

It replaces all "newlines" or \n with "<br>". In other words, "NewLine 2
(to) BReak". You could add the breaks into the database being input
(Record - Before Insert, Before Update), but it's just as easy to use this
to change the display on each page that the data shows up on (Grid - Before
Show).

michael

"Steven Dowd" <newspost@dowd.co.uk> wrote in message
news:ap2cvi$c9u$1@news.codecharge.com...
> I have two large text area's in a page , and needed to clean
> the page breaks text etc
> so i took a look through a few of the sample CC2 codes
> and found that in the gotocode example the inputted /
> displayed text was being cleaned with
>
> $fldxxxxxx = str_replace("\n", "<br>", $fldxxxxxxxxx );
>
> so i tried it , and it worked ..... untill i clicked 'update' and it
> went pearshaped, it doubled up on all the <br>'s
>
>
> so what was previously:
>
> text like this in a line
> <br>with a leading break beforit
> <br>like this example text
>
> has become text that is
> <br><br>formatted like this with two
> <br><br>leading breaks befor each line
>
> and if i clicked update again it gets worse
> <br><br><br>it will keep adding these extra break
> <br><br><br>tags for ever,
>
> anyways, now you have had a good laugh , what can i add
> to clean the html that doesnt add extra breaks on update
>
> i did some testing and the following
>
> $fldnews_top = str_replace("<br><br>", "", $fldnews_top );
> $fldnews_top = str_replace("<br>", "", $fldnews_top );
> $fldnews_top = str_replace("\n", "<br>", $fldnews_top );
>
> works perfectly to remove all the existing 'many' <br> tags
> and doesnt add any extra, so the page looks ok,
>
> but damn thats a bad way to do it, even i can see that, so
>
> how do i clean many breaks from my old website posts ,
> but not totally kill the site by removing 'all' the <br> tags
>
> thanks
>
> Steven Dowd
>
>
>
>


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.