用php创建php文件

I am trying to create php file with php script with php function "fopen" and "fwrite". I am not able to write two things if you can help me with that plz. Here is the script.

<?php
$fname='my-name';
$filename = "testme.php";
$ourFileName =$filename;
$ourFileHandle = fopen($ourFileName, 'w');

$written =  "
esc_html__( 'Try looking in the monthly archives. %1$s', '$fname' );
the_widget( 'Widget_Archives', 'dropdown=1', \"after_title=</h2>$$fname_archive_content\" );

";
fwrite($ourFileHandle,$written);
fclose($ourFileHandle);?>

I want to write %1$s as it is which I can't and I also want to write $fname_archive_content = $my-name_archive_content in line second. Any help plz?? Thanks for looking this question.

Escape the dollar signs with \, and enclose the variable name with curly braces (complex variable parsing syntax).

$written =  "
esc_html__( 'Try looking in the monthly archives. %1\$s', '$fname' );
the_widget( 'Widget_Archives', 'dropdown=1', \"after_title=</h2>\${$fname}_archive_content\" );

";