Skip to content

Instantly share code, notes, and snippets.

@cereal-s
Last active December 12, 2018 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cereal-s/e8a65d853a27e9fc0c858de3fba64dfc to your computer and use it in GitHub Desktop.
Save cereal-s/e8a65d853a27e9fc0c858de3fba64dfc to your computer and use it in GitHub Desktop.
Form to XML file.
<?php
$file = 'file.xml';
if(isset($_POST))
{
$url = filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL);
$template = <<<XML
<Response>
<Play>%s</Play>
</Response>
XML;
if($url)
{
$f = fopen($file, 'w+');
fwrite($f, sprintf($template, $url));
fclose($f);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Generate XML file</title>
</head>
<body>
<form method="post">
<p>
<label for="url">URL</label>
<input type="url" name="url" id="url">
</p>
<p>
<input type="submit" name="submit" value="Generate XML">
</p>
</form>
<?php
if(file_exists($file)) {
print sprintf('<p><a href="%s">Download XML</a></p>', $file);
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment