hube hube - 8 days ago 5
PHP Question

Add echo `$` as text in php

How to add

$
as text. Something like this :

fwrite($myfile, "<?php $myarray = " . print_r($result, true) . " ?>");

Answer

If you want to write the name of the array as you show here, then add a slash before the dollar sign to escape it.

fwrite($myfile, "<?php \$myarray = " . print_r($result, true) . " ?>");

Or you can use single quotes, which won't process any variables:

fwrite($myfile, '<?php $myarray = ' . print_r($result, true) . ' ?>');