Re: help with nl2br

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Phillip S. Baker wrote:
> Due to style sheet stuff I need to modify the nl2br (IE create or use a
> different function).
>
> I am pulling data from a database and using nl2br, which does the
> standard.
>
> some text copy<br />
> <br />
> Some more copy<br />
>
> What I want instead is
> <p>Some text copy</p>
>
> <p>some more text copy</p>
>
> Again this is because of css and the designer I am workign with. Is there
> a
> built in function that can do something like this or another function out
> there. So far I cannot see anything. Or is there a way to view the coding
> of
> the nl2br function so I can create a new function modifying how it does
> it.
>
> Just asking so I do not have to create something from scratch.
> Thanks.

//Maybe you just want:
function nl2p($text){
  return str_replace("\n", "</P>\n<P>", $text);
}

//Or, perhaps:
function nl2p($text){
  $result = str_replace("\n\n", "</P><P>", $text);
  $result = nl2br($result);
  return $result;
}

But it might be worse than that, and you want to replace 2 OR MORE \n with
<P> tags, at which point you probably want something like:

function nl2p($text){
  $result = preg_replace("/[\n]{2,}/", "</P><P>", $text);
  //$result = nl2br($result); //Maybe uncomment...
  return $result;
}

All depends on how the original data was typed in, and what your designer
is aiming for.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux