Reputation: 421
I have a function in a class:
public function displayComments($postorpage, $id_postorpage){
$query = mysql_query("SELECT * FROM `".DB."`.`mmsv_servers_page_comments` WHERE `id_postorpage`='$id_postorpage'");
while($comment = mysql_fetch_object($query)){
$added = new Time;
$elapsed = $added->displayElapsedSignificant($comment->data);
echo "
<h3>$comment->nick</h3>
<i>$elapsed</i>
<p>".addSecurityView($comment->text)."</p>
";
}
}
And the function addSecurityView which supposes to remove the break lines doesn't work:
function addSecurityView($value)
{
$result = preg_replace(array("/\r\n\r\n/", "/\n\n/"), array("\r\n", "\n"), $value);
return $result;
}
Upvotes: 1
Views: 430
Reputation: 1038
i believe this should work with you as it works with me
<?php
$trans = array("\r" => "" , "\n" => "");
echo strtr("\n hi and \r hi", $trans);
?>
and consider on changing from MySql to MySqli or PDO
Upvotes: 1
Reputation: 1967
try this one here
$string = trim(preg_replace('/\s+/', ' ', $string));
here is nice simple SECURE output function
function secureOutput($string) {
$string = trim(preg_replace('/\s+/', ' ', $string)); //this will remove multiple whitespaces
return htmlentities($string, ENT_QUOTES);
}
Upvotes: 0
Reputation: 71
Try using strtr function, with replace pairs. http://php.net/manual/en/function.strtr.php
Upvotes: 0