Skip to content

Instantly share code, notes, and snippets.

@Tomy2e
Created August 11, 2016 01:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Tomy2e/29eab9d436b3c128cbe1d51add56a24d to your computer and use it in GitHub Desktop.
Ne garde qu'un seul exemplaire de chaque caractère parmi tous ceux donnés en entrée
<?php
header('Content-type: text/html; charset=utf-8');
if(isset($_POST['entree']))
{
$car_exists = array();
$string = preg_split('//u', $_POST['entree'], null, PREG_SPLIT_NO_EMPTY);
$nb_car_entree = mb_strlen($_POST['entree']);
$string_sortie = "";
/*foreach($string as $car)
{
if(@$car_exists[$car] == true)
{
//echo "Le caractère '$car' existe déjà.<br />";
}
else
{
$string_sortie .= $car;
$car;
$car_exists[$car] = true;
}
}*/
$string_sortie = array_unique($string);
$string_sortie = implode("",$string_sortie);
}
?>
<h1>Entrée</h1>
<form action="" method="post">
<textarea cols="100" rows="20" name="entree"><?php echo @$_POST['entree']; ?></textarea><br />
<input type="submit"/>
</form>
<h1>Sortie</h1>
<textarea cols="100" rows="20"><?php echo @$string_sortie; ?></textarea>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment