How to remove this line break?

0

I have a page that uses a text editor of type 'wysiwyg' which in the case is a textarea element, this generates an html text pro code that the user type, I save the value of this field in the onblur of the same through a ajax that does save in SESSION via php, the problem is later, I want to make this text that the user entered appears on the screen (even if the user refreshes the page), and I'm having trouble setting the text in the text editor, because the generated code is generated with line break, and when I put this value in javascript it gives error due to this line break I already looked for ways to remove those line breaks, but I did not find one that worked.

function that calls ajax:

function SalvaSession(valor){
      $.post( "ajax_salva_session.php",
            {
                'texto' : valor  //valor recebe o html do editor de texto
           },
           function (data) {
           }
      );
 }

ajax_salva_session.php file (which saves the text received from the editor):

<?php
    $texto = isset($_POST['texto']) ? $_POST['texto'] : '';
    $texto = str_replace("\n", " ", $texto); //usei essas 3 formas que achei  
    $texto = str_replace("\r", " ", $texto); //na net pra tentar eliminar a quebra
    $texto = preg_replace('/\s/',' ',$texto);//de linha, mas até o momento sem sucesso :/
    $_SESSION['capitulo'] = $texto;
?>

$('#paragrafo').Editor('setText', "<?php echo ($_SESSION['capitulo']); ?>");

text generated in the browser (which gives error):

$('#paragrafo').Editor('setText', "<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: _SESSION in C:\wamp\www\index.php on line <i>10</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0058</td><td bgcolor='#eeeeec' align='right'>241440</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\index.php' bgcolor='#eeeeec'>..\index.php<b>:</b>0</td></tr>
</table></font>
");
    
asked by anonymous 09.01.2016 / 20:02

2 answers

2

Try to give replace like this:

str_replace("> <", "><", $texto);

If this does not work, the problem may be with the quotation marks. It has a colspan="5" , with double quotes instead of simple. Since you double-checked the double quotation mark at the beginning, it considers that before 5 a closing, and after 5 a new opening.

Replace in ajax

Try to make a replace at the moment of receiving the text, replacing the double quotation marks with the simple ones.

function SalvaSession(valor){
      $.post( "ajax_salva_session.php",
            {
                'texto' : valor.replace("\"", "\'")  //valor recebe o html do editor de texto
           },
           function (data) {
           }
      );
 }
    
09.01.2016 / 20:11
1

Try this

$logradouro = htmlentities($logradouro, null, 'utf-8');
$logradouro = str_replace("&nbsp;"," ",$logradouro);
$logradouro = str_replace("\n", "", $logradouro);
$logradouro = str_replace("\r", "", $logradouro);
$logradouro = preg_replace('/\s/',' ',$logradouro);
    
20.02.2018 / 18:29