Source of sajax_linebreak.php
<?    // some kinda script
    
require("Sajax_json.php");
    
sajax_init();
    
sajax_export("sendText");
    
sajax_handle_client_request();
    
    function
sendText($txt="") {
        if (
$txt=="" ) {
            return
"";
        }
        
ob_start();
        
?>
        getElem('outText').value='<?= fix_html($txt) ?>';
        <?
        $html
= ob_get_contents();
        
ob_end_clean();
        return
$html;
    }
    
    function
fix_html($html) {
        
$patterns = array(
            
"/\n/",
            
"/\r/"
        
);
        
$replace = array(
            
"\\n",
            
"\\r"
        
);
        
$fix = addslashes($html);
        
$fix = preg_replace($patterns,$replace,$fix);
        return
$fix;    
    }
?>
<html>
<head>
    <title>Sajax linebreaks test</title>
    <script>
    <? sajax_show_javascript(); ?>
    function getElem(myId) {
        return document.getElementById(myId);
    }    
    function do_cb(result) {
        eval(result);
    }
    </script>
</head>

<body>
<center><h2>Sajax linebreaks test</h2></cente>
Type stuff here:<br />
<textarea rows="8" cols="40" id="inText" onclick="this.select()">Click Here and Type</textarea>
<button onclick="x_sendText(getElem('inText').value,do_cb);">Send Text</button>
<hr />
Response goes here:<br />
<textarea rows="8" cols="40" id="outText" readonly></textarea>
</body>
</html>