xoops forums

Forum Index


Board index » All Posts (macgeek)




macgeek

Just popping in
Posted on: 2004/9/13 14:47
macgeek
macgeek (Show more)
Just popping in
Posts: 5
Since: 2004/9/6 1
#1

Re: A fixed nl2Br -- no more extra white space

Feh. Can't get around PRE tags, but adding this above the default line works well. It eliminates line breaks around HTML tags.

//Remove white space between HTML tags and a preceding or following new line.
                //(And the new line itself.)
                
$text preg_replace("/(<.*?>)s*[rn]s*/","$1"$text);
                
$text preg_replace("/s*[rn]s*(<.*?>)/","$1"$text);


macgeek

Just popping in
Posted on: 2004/9/13 14:16
macgeek
macgeek (Show more)
Just popping in
Posts: 5
Since: 2004/9/6 1
#2

Re: A fixed nl2Br -- no more extra white space

Upon further investigation, this horks PRE tags. Still working :)


macgeek

Just popping in
Posted on: 2004/9/13 11:47
macgeek
macgeek (Show more)
Just popping in
Posts: 5
Since: 2004/9/6 1
#3

A fixed nl2Br -- no more extra white space

Coming from other CMSes I've found the way XOOPS handles text to be extremely annoying. Luckily, there were a significant amount of other things that made me use it for my upcoming site and I am, overall, quite happy. But I had to fix that damned "extra white space" problem when posting.

After hunting for a while I found it was the nl2Br function that was very, very simply-implemented. I made a smart version. This version has some simple rules:

1. If there is an HTML tag at either end, remove all white space so it doesn't get parsed. This fixes the "too much white space above the tables" problem.
2. If there are a bunch of new lines between things, put one P tag in its place.
3. It there is one new line in-between two lines, place a BR.

Enjoy.

function &nl2Br($text)
{
    
/*
    If there are two or more NLs between things, add a <p />
    If there is one NL then make it a <br />.
    
    If the last non-white-space char before the line break was
    the end of a tag, don't add anything.
    */
    
    //Remove white space between HTML tags and a preceding
    //or following new line. (And the new line itself.)
    
$text preg_replace("/(<.*?>)s*[rn]s*/","$1"$text);
    
$text preg_replace("/s*[rn]s*(<.*?>)/","$1"$text);
    
    
//Single returns become single breaks.
    //This is before the <p /> handler because it would match these as well.
    
$text preg_replace("/([^rn])rn([^rn])/","$1<br />$2"$text);
    
    
//Multiple returns become one paragraph break.
    
$text preg_replace("/[rn]+/","<p />"$text);
    
    
//Remaining chars become breaks.
    
$text preg_replace("/n/","<br />"$text);
    
$text preg_replace("/r/","<br />"$text);
    
    return 
$text;     
}


macgeek

Just popping in
Posted on: 2004/9/13 9:36
macgeek
macgeek (Show more)
Just popping in
Posts: 5
Since: 2004/9/6 1
#4

Re: Redirecting to "/Modile/News(...)"?

System Admin->Preferences->General Settings->Module for your start page



TopTop