note 109577 added to function.nl2br
| From: | ben at indietorrent dot org | Date: | Mon, 30 Jul 2012 14:12:54 +0000 |
| Subject: | note 109577 added to function.nl2br | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189465@lists.php.net to get a copy of this message | ||
If you're looking to do the reverse, that is, "break to newline", here's one
approach, which uses regular expressions and enables breaks to be replaced with any character (not
just a newline). The expression includes any amount of white-space between the characters in the
HTML break tags(s) and disregards case (that is, <br/> and <BR > will both be replaced),
and takes into account the optional "short" closing tag.
<?php
function replaceHtmlBreaks($str, $replace, $multiIstance = FALSE)
{
//The multi-instance version, which replaces any number
//of consecutive tags, including any white-space, will replace
//
//Some string <BR /><br> Another string <br /><Br />
//
//for example, with
//
//Some string.Another string.
//
//The single-instance version will replace the same string with
//
//Some string .. Another string ..
$base = '<[bB][rR][\s]*[/]*[\s]*>';
$pattern = '|' . $base . '|';
if ($multiIstance === TRUE) {
//The pipe (|) delimiter can be changed, if necessary.
$pattern = '|([\s]*' . $base . '[\s]*)+|';
}
return preg_replace($pattern, $replace, $str);
}
?>
----
Server IP: 192.41.42.26
Probable Submitter: 50.75.172.235
----
Manual Page -- http://www.php.net/manual/en/function.nl2br.php
Edit -- https://master.php.net/note/edit/109577
Del: integrated -- https://master.php.net/note/delete/109577/integrated
Del: useless -- https://master.php.net/note/delete/109577/useless
Del: bad code -- https://master.php.net/note/delete/109577/bad+code
Del: spam -- https://master.php.net/note/delete/109577/spam
Del: non-english -- https://master.php.net/note/delete/109577/non-english
Del: in docs -- https://master.php.net/note/delete/109577/in+docs
Del: other reasons-- https://master.php.net/note/delete/109577
Reject -- https://master.php.net/note/reject/109577
Search -- https://master.php.net/manage/user-notes.php