On Thu, 11 Mar 2004 20:21:33 +0100, "Marco Snoek"
<_[mps]@[webmind.nl]_Dont_you_dare_send.spam> wrote:
Hope you can help me out with this one..
nl2br($string) converts all the \n to <br \>
.. but ..
Suppose I have a table or other HTML elements in $string..
All the TD> and TR> and FORM> are trailed by <br />
How can I adjust the function:
preg_replace("/\r\n|\r|\n/", "<br>\n", $r[body])
to ignore lines ending with >
(or: > n spaces )
I think you're heading into trouble with this approach; what about the
following perfectly valid HTML:
<form method="get"
action="something.php"
name="whatever">
You've now got a whole load of other exceptions to deal with.
The idea of nl2br is to convert _non-HTML_ text data containing newlines to an
HTML equivalent that has <br> elements so that it has newlines in the same
place when inserted into an HTML document.
In general, you can't parse HTML with a single regular expression, as regular
expressions aren't capable of maintaining states as necessary to implement a
HTML parser.
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>