note 53565 deleted from function.nl2br by googleguy
| From: | googleguy@php.net | Date: | Thu, 13 Jun 2013 11:01:31 +0000 |
| Subject: | note 53565 deleted from function.nl2br by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195150@lists.php.net to get a copy of this message | ||
Note Submitter: admin at ninthcircuit dot info
----
As stated in the manual above, PHP's nl2br() feature only puts a "<br />" tag
before each newline ("\n"). So -- if you intend to code a br2nl() function for yourselves,
all you have to do is remove every occurence of "<br />" or "<br>".
Rather than get into nasty regular expressions to accomplish this, just use what PHP has built in
already -- str_replace():
<?php
/* br2nl for use with HTML forms, etc. */
function br2nl($text)
{
/* Remove XHTML linebreak tags. */
$text = str_replace("<br />","",$text);
/* Remove HTML 4.01 linebreak tags. */
$text = str_replace("<br>","",$text);
/* Return the result. */
return $text;
}
?>
The final result from this function being called is whatever was entered before XHTML/HTML
linebreaks were added.
All newlines are preserved by default, as per PHP ln2br() specification. Since the code above
preserves newlines also, you can expect your data to reappear in the same way it was entered.
Hope this helps.