I have a question I have been pondering for a while.
What is the best way of keeping line breaks to a MySQL db and handle the escapes so that the query doesn't fail.
I came up with a function to do this but I am not sure this is the right way to handle the string.
function nl2br2 ($string){
$sqlescapes = array("'", ";");
$string = str_replace($sqlescapes, "", $string);
return str_replace( "\n", '<br />', $string );
}
This function will replace PHP line breaks and replace them with <br/>
so html can recognise them if I use mysqli_real_escape_string it removes the line break and this is the predicament.
Are there any other functions I could utilise, as the above removes grammar from the string?
so html can recognise them if I use mysqli_real_escape_string it removes the line break and this is the predicament – D Jones Jan 14 '16 at 23:03