Skip to content

Instantly share code, notes, and snippets.

@azihassan
Created December 16, 2015 15:59
Show Gist options
  • Save azihassan/0e8b1734a297900b81ee to your computer and use it in GitHub Desktop.
Save azihassan/0e8b1734a297900b81ee to your computer and use it in GitHub Desktop.
SimpleXML usage example
<form method = "post">
<p><label>Nom : <input type = "text" name = "nom" /></label></p>
<p><label>Prenom : <input type = "text" name = "prenom" /></label></p>
<p><label>CIN : <input type = "text" name = "cin" /></label></p>
<p><label>Adresse : <input type = "text" name = "adresse" /></label></p>
<p><label>Email : <input type = "text" name = "email" /></label></p>
<p><input type = "submit" value = "Convertir" /></p>
</form>
<?php
if(!isset($_POST['nom'], $_POST['prenom'], $_POST['cin'], $_POST['adresse'], $_POST['email']))
exit;
$str = <<<XML
<?xml version = "1.0" ?>
<utilisateurs/>
XML;
$xml = new SimpleXMLElement($str);
$user = $xml->addChild('utilisateur');
foreach($_POST as $k => $v)
$user->addChild($k, $v);
echo '<pre>' . htmlspecialchars($xml->asXML()), '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment