自从我做了任何PHP编码以来,已经很长时间了,所以我真的回到了原来的位置,如果我错过了一些非常明显/微不足道的事情,我会提前道歉。如何在变量中放置变量PHP
我想创建一个表单,它处理并提交数据并将一段代码附加到XML文件的特定部分。
这是我有
<? $title = $_POST['title'] ;
$author = $_POST['author'];
$filesize = $_POST['filesize'];
$pubdate = $_POST['pubdate'];
$duration = $_POST['duration'];
$summary = $_POST['summary'];
$key = '<itunes:category text="Business"></itunes:category>';
$newline = '<item>
<title>$title</title>
<link>http://example.com/CS/podcast/<? php echo($target_path);?></link>
<itunes:author>$author</itunes:author>
<itunes:summary><?php echo($summary); ?></itunes:summary>
<enclosure url="http://example.com/CS/$targetpath" length="$filesize" type="audio/mpeg"/>
<guid>http://www.example.com/CS/podcast/<? php echo($target_path);?></guid>
<pubDate><?php echo($pubdate);?></pubDate>
<itunes:duration><?php echo($duration);?></itunes:duration>
<itunes:keywords>My Podcast</itunes:keywords>
<category>Podcasts</category>
<itunes:explicit>no</itunes:explicit>
</item>';
//copy file to prevent double entry
$file = "list.xml";
$newfile = "listtemp.xml";
copy($file, $newfile) or exit("failed to copy $file");
//load file into $lines array
$fc = fopen ($file, "r");
while (!feof ($fc))
{
$buffer = fgets($fc, 4096);
$lines[] = $buffer;}
fclose ($fc);
//open same file and use "w" to clear file
$f=fopen($newfile,"w") or die("couldn't open $file");
/* uncomment to debug
print_r($lines);
print "<br>\n";
*/
//loop through array using foreach
foreach($lines as $line){
fwrite($f,$line); //place $line back in file
if (strstr($line,$key)){ //look for $key in each line
fwrite($f,$newline."\n");
} //place $line back in file }
fclose($f);
copy($newfile, $file) or exit("failed to copy $newfile");
echo "done";
echo "$newline";?>
我似乎是,它完美地追加代码放到正确的地方,但显示器$标题,而不是输入标题同样是真正的问题
我认为问题在于你不能在另一个变量中有一个变量,因为如果任何人都可以将代码输入到表单中,这是否有危险?我甚至不需要严密的安全措施,因为这对于内部使用来说是不合理的。
找到
http://uk3.php.net/manual/en/function.eval.php 但未能将其善加利用。
感谢信
如果我理解正确,您希望将**实际变量**写入文件而不是其值? – MisterBla
您并不需要顶部打开关闭php标签,当你已经在PHP –