Cut text problem when creating text file

1

I need to create a file that contains PHP code. This code comes from a string like "<?php class foo{ } ?>" but when I give a echo it just cuts the reserved words.

How to turn the string into plain text without missing a word?

I will create a file by fopen .

    
asked by anonymous 28.04.2014 / 05:16

2 answers

1

Use htmlentities :

echo htmlentities($suaString);

This is only on display (it looks like your problem is there). In the text file, your string should be written without escaping anything.

    
28.04.2014 / 05:24
0

Creating and reading the file with fopen from

//Criando arquivo
$arq = fopen('arquivo.txt', 'a+');

//Gravando tags sem perder o contéudo do texto coloque aspas simples
fwrite($arq, '<?php echo $variavel; >'."\r\n");
fclose($arq);
//Lendo o arquivo
$arq = fopen('arquivo.txt', 'r');
//Pegando o conteudo
$lin = fread($arq, filesize('arquivo.txt'));
//Imprimindo o conteudo
echo  htmlentities($lin);

References: link

    
28.04.2014 / 15:17