How to remove line breaks and carriage return from a string

This is how you can remove line breaks and carriage return from a string.

<?php
$string
= trim( preg_replace( '/\s+/', ' ', $string ) );
?>
Knowledge keywords: