Text problem cut when creating text file

Asked

Viewed 146 times

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 she just cuts out the reserved words.

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

I’ll create a file by fopen.

  • 2

    Post your code and try to indicate better what the problem is. What tests you did.

2 answers

1

Use htmlentities:

echo htmlentities($suaString);

This is only when displaying (it seems that there is your problem). In the text file, your string should be saved without escaping anything.

  • OK I’ll test tonight and I’ll tell you the result. Anyway thank you!

0

Creating and reading the Archive with fopen of

//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: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

  • 1

    OK I’ll test tonight and I’ll tell you the result. Anyway thank you!

  • @Leandrocurious you tested ???

Browser other questions tagged

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