简体   繁体   中英

Creating php file with 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\" );

";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM