Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to place Variables within a Variable PHP
    primarykey
    data
    text
    <p>its been a long time since i've done any PHP coding so I'm really back to square one, apologies in advance if I am missing something really obvious/trivial.</p> <p>I am trying to create a form, which processes and submits the data and appends a piece of code to a specific section of an XML file.</p> <p>This is what I've got</p> <pre><code>&lt;? $title = $_POST['title'] ; $author = $_POST['author']; $filesize = $_POST['filesize']; $pubdate = $_POST['pubdate']; $duration = $_POST['duration']; $summary = $_POST['summary']; $key = '&lt;itunes:category text="Business"&gt;&lt;/itunes:category&gt;'; $newline = '&lt;item&gt; &lt;title&gt;$title&lt;/title&gt; &lt;link&gt;http://example.com/CS/podcast/&lt;? php echo($target_path);?&gt;&lt;/link&gt; &lt;itunes:author&gt;$author&lt;/itunes:author&gt; &lt;itunes:summary&gt;&lt;?php echo($summary); ?&gt;&lt;/itunes:summary&gt; &lt;enclosure url="http://example.com/CS/$targetpath" length="$filesize" type="audio/mpeg"/&gt; &lt;guid&gt;http://www.example.com/CS/podcast/&lt;? php echo($target_path);?&gt;&lt;/guid&gt; &lt;pubDate&gt;&lt;?php echo($pubdate);?&gt;&lt;/pubDate&gt; &lt;itunes:duration&gt;&lt;?php echo($duration);?&gt;&lt;/itunes:duration&gt; &lt;itunes:keywords&gt;My Podcast&lt;/itunes:keywords&gt; &lt;category&gt;Podcasts&lt;/category&gt; &lt;itunes:explicit&gt;no&lt;/itunes:explicit&gt; &lt;/item&gt;'; //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 "&lt;br&gt;\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";?&gt; </code></pre> <p>The issue I seem to have is that it appends the code perfectly into the right place, but displays $title instead of the inputted title the same is true of </p> <p>I think the issue is that you cannot have a variable within another variable, since it could be dangerous if anyone could just type code into forms, is there a way around this? I don't even need tight security as this would be soley for internal use.</p> <p>Found</p> <p><a href="http://uk3.php.net/manual/en/function.eval.php" rel="nofollow">http://uk3.php.net/manual/en/function.eval.php</a> but not been able to put it to good use.</p> <p>Thank-you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload