How to get the text of a file to be placed in a textarea

Asked

Viewed 40 times

-2

If I give an echo the contents of the file appear perfectly, but if I try to run this code the content even being there (echo shows) does not appear in the textarea.

$conteudo =  file_get_contents("$arquivo"); 
          
    
 $conteudo=trim($conteudo);

echo("$conteudo"); //aparece normalmente
//$conteudo = "Eu apareço"; //se eu tirar o comentário vai aparecer o texto 
          
 echo("<script>

window.parent.document.getElementById(\"id_textarea\").value=\"$conteudo\";

</script>");

  • No, this textarea is created in index, it finds the element normally because as commented above, if I switch to a string it normally puts in the textarea. Thank you.

  • Got it. What’s in this file_get_contents("$arquivo")? HTML codes?

  • actually anything, I can put text that doesn’t work, I can put tags, in fact the business is so sinister that if I put in the text the test string it doesn’t show, but if I put $content="test" after it took the content of the text it shows.

  • The problem is that if you have a line break in the content will give error in JS.

  • True, now that I’ve seen that if you have line breaks you won’t, even if you’re in Aff quotes, you have a way to solve?

  • Try it like this: $conteudo=addslashes(trim(preg_replace("/\r\n/", "", $conteudo)));

  • It was not, the console shows the same Uncaught Syntaxerror error: Invalid or Unexpected token

Show 2 more comments

1 answer

0

I just put no lugar de \" ( is not ' is `even backtick) that javascript accepted. Sometimes I love javascript as my life and sometimes it makes me want to kill myself. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.