note 102560 deleted from function.nl2br by danbrown
[email protected] Mon, 21 Feb 2011 13:01:51 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
Note Submitter: albertvanderland at gmail dot com
----
I dunno if its faster than the regex sample but it rebuilds the string, so it doesnt have \r in it. (it returns one long string without line breaks\tabs or whatever).
function nl2tag($str, $tag){
$string = "<{$tag}>";
for ($i = 0; $i < strlen($str); $i++) {
if (ord($str[$i]) > 31) {
$last = $str[$i];
$string .= $str[$i];
} elseif ($str[$i] == "\n" && $last != "\n") {
$last = $str[$i];
$string .= "</{$tag}><{$tag}>";
}
}
$string .= "</{$tag}>";
return $string;
}