[thelist] PHP nl2br - <br> and <br />

Shashank Tripathi sub at shanx.com
Sun Mar 24 16:06:01 CST 2002


Hi

    | If I were you I'd ereg_replace directly the line breaks.
    | Yeah I know it's kind of exactly what you wanted to
    | avoid, yet I don't see any other solution.


A couple of (perhaps not so important) suggestions:

1. From the PHP manual:

    Note: preg_replace(), which uses a Perl-compatible regular
    expression syntax, is often a faster alternative to
    ereg_replace().

2. In general, for text formatting etc I have found it most maintainable
to include a function of my own where I pass a string and do the
necessary formatting such as nl2br, strip_tags(), converting URL text to
actual links, removing unnecessary characters etc. This way even if PHP
folks release a new function in the future, or if I need to add a new
text based formatting to all my strings, then I need to alter my code at
only one location.

Pseudo-sagaciously,
Shanx





More information about the thelist mailing list