note 102560 deleted from function.nl2br by danbrown

From: Date: Mon, 21 Feb 2011 21:01:51 +0000
Subject: note 102560 deleted from function.nl2br by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177193@lists.php.net to get a copy of this message
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; }

« previous php.notes (#177193) next »