MAJ : Texte en binaire → Encodages de caractères
This commit is contained in:
		| @@ -23,8 +23,9 @@ Le projet est disponible sur [function.divlo.fr](https://function.divlo.fr/). | ||||
| | **filterStudents(filteredLetter, students)** | Affiche uniquement les prénoms (qui sont dans la liste) qui commence par la lettre souhaitée. | - filteredLetter : la lettre à filtré - students : la liste des prénoms  | | ||||
| | **randomQuote()** | Génère aléatoirement une citation ou un proverbe. | Aucun paramètre  | | ||||
| | **convertCurrency(value, currency, url)** | Convertis une valeur dans une devise dans une autre devise grâce à l'API [exchangeratesapi.io](https://exchangeratesapi.io/). | - value : la valeur à convertir - currency : la devise à avoir après conversion - url : l'url de la requête à l'API en fonction du paramètre dans l'url '?base=' | | ||||
| | **utf8ToBin(s)** | UTF-8 vers Binaire. | - s : la valeur à convertir  | | ||||
| | **binToUtf8(s)** | Binaire vers UTF-8. | - s : la valeur à convertir  | | ||||
| | **utf8ToBin(s)** | Texte en Binaire (UTF-8). | - s : la valeur à convertir  | | ||||
| | **binToUtf8(s)** | Binaire (UTF-8) en Texte. | - s : la valeur à convertir  | | ||||
| | **convertDecimalBinaryHexadecimal(value, option)** | Convertis des nombres de différents bases. | - value : la valeur à convertir - option : En quelle base convertir | | ||||
| | **convertArabicToRoman(nombre)** | Convertis un nombre arabe en nombre romain. | - nombre : le nombre à convertir  | | ||||
| | **convertRomanToArabic(str)** | Convertis un nombre romain en nombre arabe. | - str : le nombre romain à convertir  | | ||||
| | **armstrongNumber(nombre)** | Vérifie si un nombre fait partie des nombres d'Armstrong ou non. | - nombre : le nombre à tester  | | ||||
|   | ||||
| Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 222 KiB | 
| @@ -63,10 +63,10 @@ switch ($currentpage) { | ||||
|         $description = "Convertis une valeur dans une devise dans une autre devise."; | ||||
|         $image = 'https://function.divlo.fr/img/function-image/convertCurrency.png'; | ||||
|         break; | ||||
|     case '/views/function-views/convertBinaryText.php': | ||||
|         $title = "Conversion d'un texte en binaire et vice-versa"; | ||||
|         $description = "Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi."; | ||||
|         $image = 'https://function.divlo.fr/img/function-image/convertBinaryText.png'; | ||||
|     case '/views/function-views/convertEncoding.php': | ||||
|         $title = "Conversion des Encodages de caractères"; | ||||
|         $description = "Convertis des nombres de différentes bases et convertis en UTF-8."; | ||||
|         $image = 'https://function.divlo.fr/img/function-image/convertEncoding.png'; | ||||
|         break; | ||||
|     case '/views/function-views/convertRomanArabicNumbers.php': | ||||
|         $title = "Conversion d'un nombre arabe en nombre romain"; | ||||
|   | ||||
| @@ -184,8 +184,8 @@ function convertCurrency(value, currency, url) { | ||||
|     }); | ||||
| } | ||||
|  | ||||
| // Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi (source : http://jsfiddle.net/47zwb41o) | ||||
| // UTF-8 vers Binaire | ||||
| // Convertis des nombres de différentes bases et convertis en UTF-8. (source : http://jsfiddle.net/47zwb41o) | ||||
| // Texte en Binaire (UTF-8) | ||||
| function utf8ToBin(s) { | ||||
|     try { | ||||
|         s = unescape( encodeURIComponent(s)); | ||||
| @@ -200,18 +200,51 @@ function utf8ToBin(s) { | ||||
|         return s; | ||||
|     } | ||||
| } | ||||
| // Binaire vers UTF-8 | ||||
| // Binaire (UTF-8) en Texte | ||||
| function binToUtf8(s){ | ||||
|     try { | ||||
|         var i = 0, l = s.length, chr, out = ''; | ||||
|         for( ; i < l; i += 8){ | ||||
|             chr = parseInt( s.substr(i, 8 ), 2).toString(16); | ||||
|             out += '%' + ((chr.length % 2 == 0) ? chr : '0' + chr); | ||||
|         } | ||||
|         return decodeURIComponent(out); | ||||
|     } catch (error) { | ||||
|         return s; | ||||
| try { | ||||
|     var i = 0, l = s.length, chr, out = ''; | ||||
|     for( ; i < l; i += 8){ | ||||
|         chr = parseInt( s.substr(i, 8 ), 2).toString(16); | ||||
|         out += '%' + ((chr.length % 2 == 0) ? chr : '0' + chr); | ||||
|     } | ||||
|     return decodeURIComponent(out); | ||||
| } catch (error) { | ||||
|     return s; | ||||
| } | ||||
| } | ||||
| // Convertis des nombres de différents bases | ||||
| function convertDecimalBinaryHexadecimal(value, option) { | ||||
| try { | ||||
|     if (option === 'DecimalToBinary') { | ||||
|     value = value.replace(" ", ""); | ||||
|     return parseInt(value).toString(2); | ||||
|     } | ||||
|     else if (option === 'BinaryToDecimal') { | ||||
|     return parseInt(value, 2); | ||||
|     } | ||||
|     else if (option === 'DecimalToHexadecimal') { | ||||
|     value = value.replace(" ", ""); | ||||
|     return parseInt(value).toString(16).toUpperCase(); | ||||
|     } | ||||
|     else if (option === 'HexadecimalToDecimal') { | ||||
|     return parseInt(value, 16); | ||||
|     } | ||||
|     else if (option === 'BinaryToHexadecimal') { | ||||
|     value = parseInt(value, 2); | ||||
|     return parseInt(value).toString(16).toUpperCase(); | ||||
|     } | ||||
|     else if (option === 'HexadecimalToBinary') { | ||||
|     value = parseInt(value, 16); | ||||
|     return parseInt(value).toString(2); | ||||
|     } | ||||
|     else { | ||||
|     return messageError; | ||||
|     } | ||||
| }  | ||||
| catch (error) { | ||||
|     return messageError; | ||||
| } | ||||
| } | ||||
|  | ||||
| // Convertis un nombre arabe en nombre romain | ||||
|   | ||||
| @@ -170,30 +170,41 @@ $(function () { | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     $("#submitConvertBinaryText").click(function()  | ||||
|     $("#submitConvertEncoding").click(function()  | ||||
|     { | ||||
|         let binaryTextValue = $('#binaryTextValue').val(); | ||||
|         let convertIn = $("#convertIn option:selected").text(); | ||||
|  | ||||
|         if(isEmptyValue(binaryTextValue)) { | ||||
|             $('.results').html(emptyMessageError); | ||||
|         } | ||||
|         else if (convertIn === 'Texte') {  | ||||
|             // Le replace enlève les espaces | ||||
|             let textResult = binToUtf8(binaryTextValue.replace(/\s/g,''));  | ||||
|  | ||||
|             $('.results').html(textResult); | ||||
|         } | ||||
|         else if (convertIn === 'Binaire') { | ||||
|             // Les 2 replace permettent de rajouter un espace tout les 8 bits | ||||
|             let binaryResult = utf8ToBin(binaryTextValue); | ||||
|             binaryResult = binaryResult.replace(/(\d{8})/g, '$1 ').replace(/(^\s+|\s+$)/,'');  | ||||
|  | ||||
|             $('.results').html(binaryResult); | ||||
|         } | ||||
|         else { | ||||
|         let value = $('#value').val(); | ||||
|         let option = $("#option option:selected").val(); | ||||
|         if(isEmptyValue(value)) | ||||
|         { | ||||
|             $('.results').html(messageError); | ||||
|         } | ||||
|         else  | ||||
|         { | ||||
|           if (option === 'DecimalToBinary' || option === 'BinaryToDecimal' || option === 'DecimalToHexadecimal' || option === 'HexadecimalToDecimal' || option === 'BinaryToHexadecimal' || option === 'HexadecimalToBinary') { | ||||
|             let result = convertDecimalBinaryHexadecimal(value, option); | ||||
|             if (result === messageError || isNaN(result)) { | ||||
|               $('.results').html(messageError); | ||||
|             } else { | ||||
|               $('.results').html(result); | ||||
|             } | ||||
|           } | ||||
|           else if (option === 'BinaryToText') { | ||||
|             // Le replace enlève les espaces | ||||
|             let textResult = binToUtf8(value.replace(/\s/g,''));  | ||||
|    | ||||
|             $('.results').html(textResult); | ||||
|           } | ||||
|           else if (option === 'TextToBinary') { | ||||
|               // Les 2 replace permettent de rajouter un espace tout les 8 bits | ||||
|               let binaryResult = utf8ToBin(value); | ||||
|               binaryResult = binaryResult.replace(/(\d{8})/g, '$1 ').replace(/(^\s+|\s+$)/,'');  | ||||
|    | ||||
|               $('.results').html(binaryResult); | ||||
|           } | ||||
|           else { | ||||
|             $('.results').html(messageError); | ||||
|           } | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     $("#submitConvertRomanArabicNumbers").click(function()  | ||||
|   | ||||
| @@ -81,9 +81,9 @@ | ||||
|     <div class="row"> | ||||
|         <div class="col-sm-12 col-md-6 pb-4"> | ||||
|             <div class="feature text-center pb-5"> | ||||
|                 <h2 class="function-list-title"><a href="./function-views/convertBinaryText.php">Conversion d'un texte en binaire et vice-versa</a></h2> | ||||
|                 <a href="./function-views/convertBinaryText.php"><img class="function-list-image" src="/img/function-image/convertBinaryText.png" alt=""></a> | ||||
|                 <p class="function-list-description">Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi.</p> | ||||
|                 <h2 class="function-list-title"><a href="./function-views/convertEncoding.php">Conversion des Encodages de caractères</a></h2> | ||||
|                 <a href="./function-views/convertEncoding.php"><img class="function-list-image" src="/img/function-image/convertEncoding.png" alt=""></a> | ||||
|                 <p class="function-list-description">Convertis des nombres de différentes bases et convertis en UTF-8.</p> | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="col-sm-12 col-md-6 pb-4"> | ||||
|   | ||||
| @@ -1,35 +0,0 @@ | ||||
| <!-- Config --> | ||||
| <?php include("../../php/config.php");?> | ||||
|  | ||||
| <!-- Header --> | ||||
| <?php include("../../incl/header.php");?> | ||||
|  | ||||
| <!-- Page Content --> | ||||
| <div class="container"> | ||||
|   <h1><span class="important"><?php echo $title?></span> :</h1> | ||||
|   <p class="pt-3 text-center"><?php echo $description?></p> | ||||
|   <div class="text-center"> | ||||
|     <img class="function-image" src="/img/function-image/convertBinaryText.png" alt="Convert Binary Text"> | ||||
|   </div> | ||||
|   <div class="form-group"> | ||||
| 		<label for="binaryTextValue">Entrez votre chaîne de caractères ou du binaire :</label> | ||||
|         <textarea name="binaryTextValue" type="text" id="binaryTextValue" placeholder="(e.g : 'Salut' ou '01010011 01100001')" class="form-control"></textarea> | ||||
|         <br> | ||||
| 		<label for="convertIn">Convertir en : </label> <br> | ||||
|         <select id="convertIn"> | ||||
|             <option value="Binaire">Binaire</option> | ||||
|             <option value="Texte">Texte</option> | ||||
|         </select> | ||||
|         <div class="form-row text-center"> | ||||
|             <div class="col-12"> | ||||
|                 <br> | ||||
|                 <button type="submit" id="submitConvertBinaryText" class="btn btn-dark text-center">Envoyer</button> | ||||
|             </div> | ||||
|         </div> | ||||
|         <br> <br> | ||||
| 		<p class="results text-center"></p> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <!-- Footer --> | ||||
| <?php include("../../incl/footer.php");?> | ||||
							
								
								
									
										41
									
								
								views/function-views/convertEncoding.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								views/function-views/convertEncoding.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| <!-- Config --> | ||||
| <?php include("../../php/config.php");?> | ||||
|  | ||||
| <!-- Header --> | ||||
| <?php include("../../incl/header.php");?> | ||||
|  | ||||
| <!-- Page Content --> | ||||
| <div class="container"> | ||||
|   <h1><span class="important"><?php echo $title?></span> :</h1> | ||||
|   <p class="pt-3 text-center"><?php echo $description?></p> | ||||
|   <div class="text-center"> | ||||
|     <img class="function-image" src="/img/function-image/convertEncoding.png" alt="Convert Encoding"> | ||||
|   </div> | ||||
|   <div class="form-group"> | ||||
| 		<label for="value">Entrez votre valeur :</label> | ||||
|         <textarea name="value" type="text" id="value" placeholder="Votre valeur..." class="form-control"></textarea> | ||||
|         <br> | ||||
| 		<label for="option">Choisissez une option : </label> <br> | ||||
|         <select id="option"> | ||||
|         <option value="DecimalToBinary">Décimal en Binaire</option> | ||||
|             <option value="BinaryToDecimal">Binaire en Décimal</option> | ||||
|             <option value="DecimalToHexadecimal">Décimal en Hexadecimal</option> | ||||
|             <option value="HexadecimalToDecimal">Hexadecimal en Décimal</option> | ||||
|             <option value="BinaryToHexadecimal">Binaire en Hexadécimal</option> | ||||
|             <option value="HexadecimalToBinary">Hexadécimal en Binaire</option> | ||||
|             <option value="TextToBinary">Texte en Binaire (UTF-8)</option> | ||||
|             <option value="BinaryToText">Binaire (UTF-8) en Texte</option> | ||||
|         </select> | ||||
|         <div class="form-row text-center"> | ||||
|             <div class="col-12"> | ||||
|                 <br> | ||||
|                 <button type="submit" id="submitConvertEncoding" class="btn btn-dark text-center">Envoyer</button> | ||||
|             </div> | ||||
|         </div> | ||||
|         <br> <br> | ||||
| 		<p class="results text-center"></p> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <!-- Footer --> | ||||
| <?php include("../../incl/footer.php");?> | ||||
		Reference in New Issue
	
	Block a user