Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Replace newlines instead of inserting <br/> before them (part #36)
Browse files Browse the repository at this point in the history
  • Loading branch information
betaveros committed Jan 17, 2015
1 parent c3b54b2 commit e9e9ff2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions puzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@
//------------------------------------------------------
function displayPuzzleInfo($uid, $pid, $puzzleInfo)
{
$title = nl2br($puzzleInfo['title']);
$title = nl2br2($puzzleInfo['title']);
if ($title == NULL)
$title = '(untitled)';

$summary = nl2br($puzzleInfo['summary']);
$summary = nl2br2($puzzleInfo['summary']);
if ($summary == NULL)
$summary = '(no summary)';

$description = nl2br($puzzleInfo['description']);
$description = nl2br2($puzzleInfo['description']);
if ($description == NULL)
$description = '(no description)';

Expand Down Expand Up @@ -1183,7 +1183,7 @@ function displayComments($uid, $pid, $lastVisit)
if (USING_AWS) {
$pcomment = str_replace("=\"uploads/", "=\"https://" . AWS_BUCKET . ".s3.amazonaws.com/uploads/", $pcomment);
}
echo nl2br($pcomment);
echo nl2br2($pcomment);
echo '</td>';
echo '</tr>';
}
Expand Down
2 changes: 1 addition & 1 deletion test.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function displayPrevFeedback($uid, $pid)

echo '<tr class="feedback">';
echo '<td class="feedback">' . $pf['time'] . '</td>';
echo '<td class="feedback">' . nl2br($cleanComment) . '</td>';
echo '<td class="feedback">' . nl2br2($cleanComment) . '</td>';
echo '</tr>';
}

Expand Down
7 changes: 6 additions & 1 deletion utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ function postprodCanon($s)
$s = preg_replace('/[^a-z0-9]+/', '_', $s);
return trim($s, "_");
}

function nl2br2($s)
{
// builtin nl2br inserts <br />s before newlines instead of replacing
// which makes line breaks in <pre> tags get doubled
return str_replace("\n", '<br />', $s);
}
function postprodCanonRound($s)
{
return postprodCanon($s);
Expand Down

0 comments on commit e9e9ff2

Please sign in to comment.