0

str_replaceファイル名を入力しようとすると、値ではなく名前をファイルfff.phpに出力できません$var

<?PHP
$path_to_file = 'fff.php';
$var_str = var_export($viewer, true);
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("//","case \"13\";
$viewer =\"jjhj/jhjh/344.mp3\";  //I put value to variable 
echo $viewer ; //Here I need to print the $ and name of the variable only
break;
//",$file_contents);
file_put_contents($path_to_file,$file_contents);
echo "your file is ok";
?>

値ではなく変数の名前を置き換えようとすると、結果がどうなるかを見てください-

fff.php

<?php
$id=$_GET['id'];
switch ($id){
case "1";
$viewer = "jhhghg/pic1.jpg";
echo $viewer ;
break ;
// my str_replace starting
    case "13";
     ="jjhj/jhjh/344.mp3";  //I put value to variable but now name empty
    echo  ; //Here I need to print the $ and name of the variable only  also here
    break;
    //
    //my str_replace end
    default;
    echo"your request error";
    }
    ?>

that's my problem I need only print the variable name. How do I do that?

4

1 に答える 1

1

「$」記号 ($viewer) をエスケープするのを忘れていませんか? それらをエスケープしないと、php はそれを変数と見なし、存在しない値に置き換えます。

$file_contents = str_replace("//","case \"13\";
\$viewer =\"jjhj/jhjh/344.mp3\";  //I put value to variable 
echo \$viewer ; //Here I need to print the \$ and name of the variable only
break;
于 2013-01-24T15:24:33.097 に答える